Finalise block breaking, (water calculations omitted because of no access to server api)

This commit is contained in:
William Johnstone 2020-03-27 23:39:53 +00:00
parent 60662ae06c
commit 0caee67e43
4 changed files with 7 additions and 10 deletions

View file

@ -53,6 +53,7 @@ public class PlayerEntity extends LivingEntity {
private boolean playerList = true;
private final EntityEffectCache effectCache;
public PlayerEntity(GameProfile gameProfile, long entityId, long geyserId, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, EntityType.PLAYER, position, motion, rotation);

View file

@ -47,12 +47,15 @@ public class Registry<T> {
BEDROCK.MAP.put(clazz, translator);
}
@SuppressWarnings("unchecked")
public <P extends T> boolean translate(Class<? extends P> clazz, P packet, GeyserSession session) {
if (!session.getUpstream().isClosed() && !session.isClosed()) {
try {
if (MAP.containsKey(clazz)) {
((PacketTranslator<P>) MAP.get(clazz)).translate(packet, session);
return true;
} else {
GeyserConnector.getInstance().getLogger().debug("Could not find packet for " + (packet.toString().length() > 25 ? packet.getClass().getSimpleName() : packet));
}
} catch (Throwable ex) {
GeyserConnector.getInstance().getLogger().error("Could not translate packet " + packet.getClass().getSimpleName(), ex);

View file

@ -65,12 +65,9 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
if (item != null) {
itemEntry = TranslatorsInit.getItemTranslator().getItem(item);
nbtData = item.getNbt();
System.out.println("item.getNbt() = " + item.getNbt());
}
double breakTime = Math.ceil(BlockUtils.getBreakTime(blockHardness, packet.getNewState().getId(), itemEntry, nbtData, session.getPlayerEntity()) * 20);
System.out.println("breakTime = " + breakTime);
int data = (int) (65535 / breakTime);
System.out.println("data = " + data);
levelEvent.setData((int) (65535 / breakTime));
session.getUpstream().sendPacket(levelEvent);
break;

View file

@ -65,11 +65,8 @@ public class BlockUtils {
private static double calculateBreakTime(double blockHardness, String toolTier, boolean canHarvestWithHand, boolean correctTool,
String toolType, boolean isWoolBlock, boolean isCobweb, int toolEfficiencyLevel, int hasteLevel, int miningFatigueLevel
/*boolean insideOfWaterWithoutAquaAffinity, boolean outOfWaterButNotOnGround*/) {
System.out.println("blockHardness = " + blockHardness);
double baseTime = ((correctTool || canHarvestWithHand) ? 1.5 : 5.0) * blockHardness;
System.out.println("baseTime = " + baseTime);
double speed = 1.0 / baseTime;
System.out.println("speed = " + speed);
if (correctTool) {
speed *= toolBreakTimeBonus(toolType, toolTier, isWoolBlock);
@ -77,9 +74,7 @@ public class BlockUtils {
} else if (toolType.equals("sword")) {
speed*= (isCobweb ? 15.0 : 1.5);
}
System.out.println("speed before haste = " + speed);
speed *= 1.0 + (0.2 * hasteLevel);
System.out.println("speed = " + speed);
switch (miningFatigueLevel) {
case 0:
@ -97,10 +92,10 @@ public class BlockUtils {
speed -= (speed * 0.99919);
break;
}
System.out.println("miningFatigueLevel = " + miningFatigueLevel);
//if (insideOfWaterWithoutAquaAffinity) speed *= 0.2;
//if (outOfWaterButNotOnGround) speed *= 0.2;
// else if insideWaterAndNotOnGround speed *= 0.2;
return 1.0 / speed;
}
@ -121,6 +116,7 @@ public class BlockUtils {
int toolEfficiencyLevel = ItemUtils.getEnchantmentLevel(nbtData, "minecraft:efficiency");
int hasteLevel = player.getEffectCache().getEffectLevel(Effect.FASTER_DIG);
int miningFatigueLevel = player.getEffectCache().getEffectLevel(Effect.SLOWER_DIG);
// TODO implement these checks and material check if possible
//boolean insideOfWaterWithoutAquaAffinity = player.isInsideOfWater() &&
// Optional.ofNullable(player.getInventory().getHelmet().getEnchantment(Enchantment.ID_WATER_WORKER))