Improve an issue to do with block breaking ghosting back, note this is not a fully fix, but improves the issue quite a bit.

This commit is contained in:
Myles 2016-04-13 16:54:18 +01:00
parent 4c7b50d6fb
commit e6671513f2
6 changed files with 62 additions and 3 deletions

View File

@ -393,6 +393,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
return getConfig().getDouble("hologram-y", -1D);
}
public boolean isBlockBreakPatch() {
return getConfig().getBoolean("block-break-patch", true);
}
public boolean isAutoTeam() {
// Collision has to be enabled first
return isPreventCollision() && getConfig().getBoolean("auto-team", true);

View File

@ -93,4 +93,11 @@ public interface ViaVersionConfig {
* @return true if automatic teaming is enabled
*/
boolean isAutoTeam();
/**
* Get if our block break patch is enabled to prevent weird ghost glitches.
*
* @return true if it is enabled.
*/
boolean isBlockBreakPatch();
}

View File

@ -1,12 +1,14 @@
package us.myles.ViaVersion.api.minecraft;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@AllArgsConstructor
@Getter
@ToString
@EqualsAndHashCode
public class Position {
private Long x;
private Long y;

View File

@ -6,7 +6,6 @@ import org.spacehq.opennbt.tag.builtin.StringTag;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -174,11 +173,34 @@ public class WorldPackets {
});
}
});
// Block Change Packet
protocol.registerOutgoing(State.PLAY, 0x23, 0x0B, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION);
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position pos = wrapper.user().get(EntityTracker.class).getCurrentlyDigging();
if (pos != null) {
if (wrapper.get(Type.POSITION, 0).equals(pos)) {
// cancel this one
if (wrapper.get(Type.VAR_INT, 0) != 0) {
wrapper.cancel();
wrapper.user().get(EntityTracker.class).setCurrentlyDigging(null);
}
}
}
}
});
}
});
/* Packets which do not have any field remapping or handlers */
protocol.registerOutgoing(State.PLAY, 0x25, 0x08); // Block Break Animation Packet
protocol.registerOutgoing(State.PLAY, 0x24, 0x0A); // Block Action Packet
protocol.registerOutgoing(State.PLAY, 0x23, 0x0B); // Block Change Packet
protocol.registerOutgoing(State.PLAY, 0x22, 0x10); // Multi Block Change Packet
protocol.registerOutgoing(State.PLAY, 0x27, 0x1C); // Explosion Packet
protocol.registerOutgoing(State.PLAY, 0x2A, 0x22); // Particle Packet
@ -228,6 +250,26 @@ public class WorldPackets {
}
}
});
// Digging patch (prevents it glitching)
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if(!ViaVersion.getConfig().isBlockBreakPatch()) return;
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
final Position block = wrapper.get(Type.POSITION, 0);
int status = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (status == 0) {
entityTracker.setCurrentlyDigging(null);
}
if (status == 1) {
entityTracker.setCurrentlyDigging(null);
}
if (status == 2) {
entityTracker.setCurrentlyDigging(block);
}
}
});
}
});

View File

@ -44,6 +44,8 @@ public class EntityTracker extends StoredObject {
private Long lastPlaceBlock = -1L;
@Setter
private int entityID;
@Setter
private Position currentlyDigging = null;
private boolean teamExists = false;
public EntityTracker(UserConnection user) {

View File

@ -27,3 +27,5 @@ use-new-deathmessages: false
# This will suppress the following error: 'Unable to get entity for ID: xxxx'
# This error message means one of you plugins is sending bad packets!
suppress-entityid-errors: false
# Our patch for block breaking issue, if you have issues with block updates then disable this.
block-break-patch: true