made the swamp homi not accept converted moss stone

This commit is contained in:
Ellpeck 2020-01-26 00:43:12 +01:00
parent 040f48b612
commit 5e8e434925
4 changed files with 39 additions and 9 deletions

View file

@ -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<BlockPos> 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())

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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<String, ItemStackHandlerNA> enderStorages = new HashMap<>();
public final ListMultimap<ResourceLocation, Tuple<Vec3d, Integer>> effectPowders = ArrayListMultimap.create();
public final List<BlockPos> 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