forked from GeyserMC/Geyser
Finalise block breaking, (water calculations omitted because of no access to server api)
This commit is contained in:
parent
60662ae06c
commit
0caee67e43
4 changed files with 7 additions and 10 deletions
|
@ -53,6 +53,7 @@ public class PlayerEntity extends LivingEntity {
|
||||||
private boolean playerList = true;
|
private boolean playerList = true;
|
||||||
private final EntityEffectCache effectCache;
|
private final EntityEffectCache effectCache;
|
||||||
|
|
||||||
|
|
||||||
public PlayerEntity(GameProfile gameProfile, long entityId, long geyserId, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public PlayerEntity(GameProfile gameProfile, long entityId, long geyserId, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
super(entityId, geyserId, EntityType.PLAYER, position, motion, rotation);
|
super(entityId, geyserId, EntityType.PLAYER, position, motion, rotation);
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,15 @@ public class Registry<T> {
|
||||||
BEDROCK.MAP.put(clazz, translator);
|
BEDROCK.MAP.put(clazz, translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <P extends T> boolean translate(Class<? extends P> clazz, P packet, GeyserSession session) {
|
public <P extends T> boolean translate(Class<? extends P> clazz, P packet, GeyserSession session) {
|
||||||
if (!session.getUpstream().isClosed() && !session.isClosed()) {
|
if (!session.getUpstream().isClosed() && !session.isClosed()) {
|
||||||
try {
|
try {
|
||||||
if (MAP.containsKey(clazz)) {
|
if (MAP.containsKey(clazz)) {
|
||||||
((PacketTranslator<P>) MAP.get(clazz)).translate(packet, session);
|
((PacketTranslator<P>) MAP.get(clazz)).translate(packet, session);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
GeyserConnector.getInstance().getLogger().debug("Could not find packet for " + (packet.toString().length() > 25 ? packet.getClass().getSimpleName() : packet));
|
||||||
}
|
}
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
GeyserConnector.getInstance().getLogger().error("Could not translate packet " + packet.getClass().getSimpleName(), ex);
|
GeyserConnector.getInstance().getLogger().error("Could not translate packet " + packet.getClass().getSimpleName(), ex);
|
||||||
|
|
|
@ -65,12 +65,9 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
itemEntry = TranslatorsInit.getItemTranslator().getItem(item);
|
itemEntry = TranslatorsInit.getItemTranslator().getItem(item);
|
||||||
nbtData = item.getNbt();
|
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);
|
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);
|
int data = (int) (65535 / breakTime);
|
||||||
System.out.println("data = " + data);
|
|
||||||
levelEvent.setData((int) (65535 / breakTime));
|
levelEvent.setData((int) (65535 / breakTime));
|
||||||
session.getUpstream().sendPacket(levelEvent);
|
session.getUpstream().sendPacket(levelEvent);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -63,13 +63,10 @@ public class BlockUtils {
|
||||||
|
|
||||||
//http://minecraft.gamepedia.com/Breaking
|
//http://minecraft.gamepedia.com/Breaking
|
||||||
private static double calculateBreakTime(double blockHardness, String toolTier, boolean canHarvestWithHand, boolean correctTool,
|
private static double calculateBreakTime(double blockHardness, String toolTier, boolean canHarvestWithHand, boolean correctTool,
|
||||||
String toolType, boolean isWoolBlock, boolean isCobweb, int toolEfficiencyLevel, int hasteLevel, int miningFatigueLevel
|
String toolType, boolean isWoolBlock, boolean isCobweb, int toolEfficiencyLevel, int hasteLevel, int miningFatigueLevel
|
||||||
/*boolean insideOfWaterWithoutAquaAffinity, boolean outOfWaterButNotOnGround*/) {
|
/*boolean insideOfWaterWithoutAquaAffinity, boolean outOfWaterButNotOnGround*/) {
|
||||||
System.out.println("blockHardness = " + blockHardness);
|
|
||||||
double baseTime = ((correctTool || canHarvestWithHand) ? 1.5 : 5.0) * blockHardness;
|
double baseTime = ((correctTool || canHarvestWithHand) ? 1.5 : 5.0) * blockHardness;
|
||||||
System.out.println("baseTime = " + baseTime);
|
|
||||||
double speed = 1.0 / baseTime;
|
double speed = 1.0 / baseTime;
|
||||||
System.out.println("speed = " + speed);
|
|
||||||
|
|
||||||
if (correctTool) {
|
if (correctTool) {
|
||||||
speed *= toolBreakTimeBonus(toolType, toolTier, isWoolBlock);
|
speed *= toolBreakTimeBonus(toolType, toolTier, isWoolBlock);
|
||||||
|
@ -77,9 +74,7 @@ public class BlockUtils {
|
||||||
} else if (toolType.equals("sword")) {
|
} else if (toolType.equals("sword")) {
|
||||||
speed*= (isCobweb ? 15.0 : 1.5);
|
speed*= (isCobweb ? 15.0 : 1.5);
|
||||||
}
|
}
|
||||||
System.out.println("speed before haste = " + speed);
|
|
||||||
speed *= 1.0 + (0.2 * hasteLevel);
|
speed *= 1.0 + (0.2 * hasteLevel);
|
||||||
System.out.println("speed = " + speed);
|
|
||||||
|
|
||||||
switch (miningFatigueLevel) {
|
switch (miningFatigueLevel) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -97,10 +92,10 @@ public class BlockUtils {
|
||||||
speed -= (speed * 0.99919);
|
speed -= (speed * 0.99919);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
System.out.println("miningFatigueLevel = " + miningFatigueLevel);
|
|
||||||
|
|
||||||
//if (insideOfWaterWithoutAquaAffinity) speed *= 0.2;
|
//if (insideOfWaterWithoutAquaAffinity) speed *= 0.2;
|
||||||
//if (outOfWaterButNotOnGround) speed *= 0.2;
|
//if (outOfWaterButNotOnGround) speed *= 0.2;
|
||||||
|
// else if insideWaterAndNotOnGround speed *= 0.2;
|
||||||
return 1.0 / speed;
|
return 1.0 / speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +116,7 @@ public class BlockUtils {
|
||||||
int toolEfficiencyLevel = ItemUtils.getEnchantmentLevel(nbtData, "minecraft:efficiency");
|
int toolEfficiencyLevel = ItemUtils.getEnchantmentLevel(nbtData, "minecraft:efficiency");
|
||||||
int hasteLevel = player.getEffectCache().getEffectLevel(Effect.FASTER_DIG);
|
int hasteLevel = player.getEffectCache().getEffectLevel(Effect.FASTER_DIG);
|
||||||
int miningFatigueLevel = player.getEffectCache().getEffectLevel(Effect.SLOWER_DIG);
|
int miningFatigueLevel = player.getEffectCache().getEffectLevel(Effect.SLOWER_DIG);
|
||||||
|
|
||||||
// TODO implement these checks and material check if possible
|
// TODO implement these checks and material check if possible
|
||||||
//boolean insideOfWaterWithoutAquaAffinity = player.isInsideOfWater() &&
|
//boolean insideOfWaterWithoutAquaAffinity = player.isInsideOfWater() &&
|
||||||
// Optional.ofNullable(player.getInventory().getHelmet().getEnchantment(Enchantment.ID_WATER_WORKER))
|
// Optional.ofNullable(player.getInventory().getHelmet().getEnchantment(Enchantment.ID_WATER_WORKER))
|
||||||
|
|
Loading…
Reference in a new issue