diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityMossGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityMossGenerator.java index 8ce186de..e28175c0 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityMossGenerator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityMossGenerator.java @@ -2,6 +2,8 @@ package de.ellpeck.naturesaura.blocks.tiles; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.api.misc.IWorldData; +import de.ellpeck.naturesaura.misc.WorldData; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketParticles; import net.minecraft.block.Block; @@ -23,6 +25,7 @@ public class TileEntityMossGenerator extends TileEntityImpl implements ITickable if (!this.world.isRemote) { if (this.world.getGameTime() % 20 != 0) return; + WorldData data = (WorldData) IWorldData.getWorldData(this.world); List possibleOffsets = new ArrayList<>(); int range = 2; @@ -30,9 +33,15 @@ public class TileEntityMossGenerator extends TileEntityImpl implements ITickable for (int y = -range; y <= range; y++) for (int z = -range; z <= range; z++) { BlockPos offset = this.pos.add(x, y, z); + boolean isRecent = data.recentlyConvertedMossStones.contains(offset); BlockState state = this.world.getBlockState(offset); - if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) + if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) { + if (isRecent) + continue; possibleOffsets.add(offset); + } else if (isRecent) { + data.recentlyConvertedMossStones.remove(offset); + } } if (possibleOffsets.isEmpty()) diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/Pickaxe.java b/src/main/java/de/ellpeck/naturesaura/items/tools/Pickaxe.java index 95ba7938..0ae94a7f 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/Pickaxe.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/Pickaxe.java @@ -3,7 +3,9 @@ package de.ellpeck.naturesaura.items.tools; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.misc.IWorldData; import de.ellpeck.naturesaura.items.ModItems; +import de.ellpeck.naturesaura.misc.WorldData; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModelProvider; import de.ellpeck.naturesaura.reg.ModRegistry; @@ -14,7 +16,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; import net.minecraft.item.PickaxeItem; import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.*; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.ICapabilityProvider; @@ -46,10 +50,16 @@ public class Pickaxe extends PickaxeItem implements IModItem, IModelProvider { BlockState state = world.getBlockState(pos); BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.get(state); if (result != null) { - if (!world.isRemote) + if (!world.isRemote) { world.setBlockState(pos, result); + + WorldData data = (WorldData) IWorldData.getWorldData(world); + data.recentlyConvertedMossStones.add(pos); + if (data.recentlyConvertedMossStones.size() > 512) + data.recentlyConvertedMossStones.remove(0); + } world.playSound(player, pos, SoundEvents.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F); - stack.damageItem(15, player, playerEntity -> {}); + stack.damageItem(15, player, playerEntity -> playerEntity.sendBreakAnimation(context.getHand())); return ActionResultType.SUCCESS; } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/Shovel.java b/src/main/java/de/ellpeck/naturesaura/items/tools/Shovel.java index 214d8489..20a76f08 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/Shovel.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/Shovel.java @@ -70,7 +70,7 @@ public class Shovel extends ShovelItem implements IModItem, IModelProvider { if (damage > 0) { world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F); - stack.damageItem(damage, player, playerEntity -> {}); + stack.damageItem(damage, player, playerEntity -> playerEntity.sendBreakAnimation(context.getHand())); return ActionResultType.SUCCESS; } } diff --git a/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java b/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java index 8d4bb114..04a8965e 100644 --- a/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java +++ b/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java @@ -11,21 +11,24 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.LongNBT; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Tuple; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; +import java.util.*; public class WorldData implements IWorldData { private final Map enderStorages = new HashMap<>(); public final ListMultimap> effectPowders = ArrayListMultimap.create(); + public final List recentlyConvertedMossStones = new ArrayList<>(); @Nullable @Override @@ -48,18 +51,26 @@ public class WorldData implements IWorldData { } compound.put("storages", storages); + ListNBT moss = new ListNBT(); + for (BlockPos pos : this.recentlyConvertedMossStones) + moss.add(new LongNBT(pos.toLong())); + compound.put("converted_moss", moss); + return compound; } @Override public void deserializeNBT(CompoundNBT compound) { this.enderStorages.clear(); - ListNBT storages = compound.getList("storages", 10); - for (INBT base : storages) { + for (INBT base : compound.getList("storages", 10)) { CompoundNBT storageComp = (CompoundNBT) base; ItemStackHandlerNA storage = this.getEnderStorage(storageComp.getString("name")); storage.deserializeNBT(storageComp); } + + this.recentlyConvertedMossStones.clear(); + for (INBT base : compound.getList("converted_moss", Constants.NBT.TAG_LONG)) + this.recentlyConvertedMossStones.add(BlockPos.fromLong(((LongNBT) base).getLong())); } @Override