From 4a15fbcec36974b7bae71d5e937568bd004a5079 Mon Sep 17 00:00:00 2001 From: Snownee Date: Sun, 31 Jan 2021 15:28:14 +0800 Subject: [PATCH] Fix funnel filter dupe --- .../content/curiosities/zapper/ZapperItem.java | 4 ++-- .../zapper/blockzapper/BlockzapperItem.java | 2 +- .../zapper/terrainzapper/TerrainTools.java | 11 ++++++----- .../zapper/terrainzapper/WorldshaperItem.java | 2 +- .../create/foundation/utility/NBTProcessors.java | 12 ++++++++++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java index 13ed0a475..44303bf94 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java @@ -241,11 +241,11 @@ public abstract class ZapperItem extends Item { return UseAction.NONE; } - public static void setTileData(World world, BlockPos pos, BlockState state, CompoundNBT data) { + public static void setTileData(World world, BlockPos pos, BlockState state, CompoundNBT data, PlayerEntity player) { if (data != null && AllBlockTags.SAFE_NBT.matches(state)) { TileEntity tile = world.getTileEntity(pos); if (tile != null) { - data = NBTProcessors.process(tile, data, true); + data = NBTProcessors.process(tile, data, !player.isCreative()); if (data == null) return; data.putInt("x", pos.getX()); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java index 954d06daf..21d555b6b 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java @@ -135,7 +135,7 @@ public class BlockzapperItem extends ZapperItem { blocksnapshot.restore(true, false); return false; } - setTileData(world, placed, state, data); + setTileData(world, placed, state, data, player); if (player instanceof ServerPlayerEntity && world instanceof ServerWorld) { ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player; diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainTools.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainTools.java index abd142734..3abb7fe27 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainTools.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainTools.java @@ -10,6 +10,7 @@ import com.simibubi.create.foundation.utility.Lang; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -36,7 +37,7 @@ public enum TerrainTools { return this != Clear && this != Flatten; } - public void run(World world, List targetPositions, Direction facing, @Nullable BlockState paintedState, @Nullable CompoundNBT data) { + public void run(World world, List targetPositions, Direction facing, @Nullable BlockState paintedState, @Nullable CompoundNBT data, PlayerEntity player) { switch (this) { case Clear: targetPositions.forEach(p -> world.setBlockState(p, Blocks.AIR.getDefaultState())); @@ -47,7 +48,7 @@ public enum TerrainTools { if (!isReplaceable(toReplace)) return; world.setBlockState(p, paintedState); - ZapperItem.setTileData(world, p, paintedState, data); + ZapperItem.setTileData(world, p, paintedState, data, player); }); break; case Flatten: @@ -67,13 +68,13 @@ public enum TerrainTools { if (!isReplaceable(toReplace)) return; world.setBlockState(p, paintedState); - ZapperItem.setTileData(world, p, paintedState, data); + ZapperItem.setTileData(world, p, paintedState, data, player); }); break; case Place: targetPositions.forEach(p -> { world.setBlockState(p, paintedState); - ZapperItem.setTileData(world, p, paintedState, data); + ZapperItem.setTileData(world, p, paintedState, data, player); }); break; case Replace: @@ -82,7 +83,7 @@ public enum TerrainTools { if (isReplaceable(toReplace)) return; world.setBlockState(p, paintedState); - ZapperItem.setTileData(world, p, paintedState, data); + ZapperItem.setTileData(world, p, paintedState, data, player); }); break; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItem.java index 9f2e4d019..4e5df7686 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItem.java @@ -77,7 +77,7 @@ public class WorldshaperItem extends ZapperItem { for (BlockPos blockPos : brush.getIncludedPositions()) affectedPositions.add(targetPos.add(blockPos)); PlacementPatterns.applyPattern(affectedPositions, stack); - tool.run(world, affectedPositions, raytrace.getFace(), stateToUse, data); + tool.run(world, affectedPositions, raytrace.getFace(), stateToUse, data, player); return true; } diff --git a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java index 8ca4d212f..1524913fb 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java @@ -6,6 +6,10 @@ import java.util.function.UnaryOperator; import javax.annotation.Nullable; +import com.simibubi.create.AllTileEntities; +import com.simibubi.create.content.logistics.item.filter.FilterItem; + +import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; @@ -35,6 +39,14 @@ public final class NBTProcessors { } return data; }); + addSurvivalProcessor(AllTileEntities.FUNNEL.get(), data -> { + if (data.contains("Filter")) { + ItemStack filter = ItemStack.read(data.getCompound("Filter")); + if (filter.getItem() instanceof FilterItem) + data.remove("Filter"); + } + return data; + }); } private NBTProcessors() {