Fixed a huge issue

Closes #90
This commit is contained in:
Ellpeck 2020-03-14 03:10:56 +01:00
parent 21963f782d
commit 444aae4bea
3 changed files with 22 additions and 3 deletions

View file

@ -6,12 +6,14 @@ import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura;
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.chunk.AuraChunk;
import de.ellpeck.naturesaura.chunk.AuraChunkProvider;
import de.ellpeck.naturesaura.commands.CommandAura;
import de.ellpeck.naturesaura.misc.WorldData;
import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
@ -21,6 +23,7 @@ import net.minecraft.world.server.ChunkManager;
import net.minecraft.world.server.ServerChunkProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
@ -47,6 +50,18 @@ public class CommonEvents {
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "data"), new WorldData());
}
@SubscribeEvent
public void onItemUse(PlayerInteractEvent.RightClickBlock event) {
PlayerEntity player = event.getPlayer();
if (player.world.isRemote)
return;
ItemStack held = event.getItemStack();
if (!held.isEmpty() && held.getItem().getRegistryName().getPath().contains("chisel")) {
WorldData data = (WorldData) IWorldData.getWorldData(player.world);
data.addMossStone(event.getPos());
}
}
@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent event) {
if (!event.world.isRemote && event.phase == TickEvent.Phase.END) {

View file

@ -55,9 +55,7 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
world.setBlockState(pos, result);
WorldData data = (WorldData) IWorldData.getWorldData(world);
data.recentlyConvertedMossStones.add(pos);
if (data.recentlyConvertedMossStones.size() > 512)
data.recentlyConvertedMossStones.remove(0);
data.addMossStone(pos);
}
world.playSound(player, pos, SoundEvents.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
stack.damageItem(15, player, playerEntity -> playerEntity.sendBreakAnimation(context.getHand()));

View file

@ -90,4 +90,10 @@ public class WorldData implements IWorldData {
}
return false;
}
public void addMossStone(BlockPos pos) {
this.recentlyConvertedMossStones.add(pos);
if (this.recentlyConvertedMossStones.size() > 512)
this.recentlyConvertedMossStones.remove(0);
}
}