Crafting Dead Modpack

Crafting Dead Modpack

111k Downloads

Validation uses gun capability not from snapshot

Afarion1 opened this issue ยท 4 comments

commented

Probably can be abused by quickly switching weapons

public static boolean handle(ValidateLivingHitMessage msg, Supplier<NetworkEvent.Context> ctx) {
ServerPlayerEntity playerEntity = ctx.get().getSender();
playerEntity.getCapability(ModCapabilities.LIVING).ifPresent(living -> {
ItemStack heldStack = playerEntity.getHeldItemMainhand();
heldStack.getCapability(ModCapabilities.GUN).ifPresent(gun -> {
for (Map.Entry<Long, Integer> hit : msg.hits.entrySet()) {
Entity hitEntity = playerEntity.getEntityWorld().getEntityByID(hit.getValue());
hitEntity.getCapability(ModCapabilities.LIVING).ifPresent(hitLiving -> {
gun.validateLivingHit(living, heldStack, hitLiving, hit.getKey());
});
}
});
});
return true;
}

commented

That's why I do a trigger pressed check in the validate method to ensure they are actually shooting with that gun.

commented

Then some shots will not register, especially if a player has high latency?

commented

That's true, goes back to what you said about validation packets being buffered. I'll clean the system up.

commented

This should be fine as the hit packet will still be in the correct order as it comes from the same client as the change weapon packet.
In addition, I've reduced the packet interval for hit validations.