actually fix Counter

This commit is contained in:
CreepyCre 2021-02-14 16:00:10 +01:00
parent ea945981de
commit 7e6a142190
2 changed files with 10 additions and 15 deletions

View file

@ -79,8 +79,11 @@ public class RiftConfigurationToolItem extends ModItem {
@Override
public TypedActionResult<Boolean> onAttackBlock(World world, PlayerEntity player, Hand hand, BlockPos pos, Direction direction) {
if (world.isClient) {
if (player.isSneaking() && Counter.get(player.getStackInHand(hand)).count() != -1 || world.getBlockEntity(pos) instanceof RiftBlockEntity) {
return TypedActionResult.success(true);
if (player.isSneaking()) {
if (Counter.get(player.getStackInHand(hand)).count() != 0 || world.getBlockEntity(pos) instanceof RiftBlockEntity) {
return TypedActionResult.success(true);
}
return TypedActionResult.fail(false);
}
} else {
ItemStack stack = player.getStackInHand(hand);
@ -93,8 +96,8 @@ public class RiftConfigurationToolItem extends ModItem {
EntityUtils.chat(player, Text.of("Rift stripped of data and set to invalid id: -1"));
return TypedActionResult.success(false);
}
} else if (Counter.get(stack).count() != -1) {
Counter.get(stack).set(-1);
} else if (Counter.get(stack).count() != 0) {
Counter.get(stack).reset();
sync(stack, player, hand);
EntityUtils.chat(player, Text.of("Counter has been reset."));
@ -113,13 +116,6 @@ public class RiftConfigurationToolItem extends ModItem {
}
}
@Override
public ItemStack getDefaultStack() {
ItemStack defaultStack = super.getDefaultStack();
Counter.get(defaultStack).set(-1);
return defaultStack;
}
// TODO: put in ServerPacketHandler
private void sync(ItemStack stack, PlayerEntity player, Hand hand) {
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;

View file

@ -14,16 +14,15 @@ public class Counter implements Component {
}
public int increment() {
this.counter++;
return this.counter;
return this.counter++;
}
public int count() {
return this.counter;
}
public void set(int value) {
this.counter = value;
public void reset() {
this.counter = 0;
}
public static <T> Counter get(T provider) {