From b247b8fba180d254dd469e822b1ceac5773d5646 Mon Sep 17 00:00:00 2001 From: malte0811 Date: Sat, 5 May 2018 20:42:47 +0200 Subject: [PATCH] Fix pick-block not working on feedthroughs and creating item entities (when it is working) if the block would drop multiple items, closes #2984 --- .../client/models/obj/IEOBJLoader.java | 15 ++++---- .../common/blocks/BlockIETileProvider.java | 7 ++-- .../common/blocks/IEBlockInterfaces.java | 20 +++++++++- .../common/blocks/metal/BlockConnector.java | 3 +- .../blocks/metal/TileEntityFeedthrough.java | 38 +++++++++++++------ .../common/util/Utils.java | 11 ++++-- 6 files changed, 65 insertions(+), 29 deletions(-) diff --git a/src/main/java/blusunrize/immersiveengineering/client/models/obj/IEOBJLoader.java b/src/main/java/blusunrize/immersiveengineering/client/models/obj/IEOBJLoader.java index 6cd0a64b46..5f9a09820d 100644 --- a/src/main/java/blusunrize/immersiveengineering/client/models/obj/IEOBJLoader.java +++ b/src/main/java/blusunrize/immersiveengineering/client/models/obj/IEOBJLoader.java @@ -17,6 +17,7 @@ import net.minecraftforge.client.model.obj.OBJLoader; import net.minecraftforge.client.model.obj.OBJModel; +import javax.annotation.Nonnull; import java.util.*; public class IEOBJLoader implements ICustomModelLoader @@ -34,32 +35,32 @@ public void addDomain(String domain) } @Override - public boolean accepts(ResourceLocation modelLocation) + public boolean accepts(@Nonnull ResourceLocation modelLocation) { return enabledDomains.contains(modelLocation.getResourceDomain()) && modelLocation.getResourcePath().endsWith(".obj.ie"); } + @Nonnull @Override - public IModel loadModel(ResourceLocation modelLocation) throws Exception + public IModel loadModel(@Nonnull ResourceLocation modelLocation) throws Exception { - ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath()); - if(!cache.containsKey(file)) + if(!cache.containsKey(modelLocation)) { IModel model = OBJLoader.INSTANCE.loadModel(modelLocation); if(model instanceof OBJModel) { - IEOBJModel ieobj = new IEOBJModel(((OBJModel)model).getMatLib(), file); + IEOBJModel ieobj = new IEOBJModel(((OBJModel)model).getMatLib(), modelLocation); cache.put(modelLocation, ieobj); } } - IEOBJModel model = cache.get(file); + IEOBJModel model = cache.get(modelLocation); if(model == null) return ModelLoaderRegistry.getMissingModel(); return model; } @Override - public void onResourceManagerReload(IResourceManager resourceManager) + public void onResourceManagerReload(@Nonnull IResourceManager resourceManager) { this.manager = resourceManager; cache.clear(); diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/BlockIETileProvider.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/BlockIETileProvider.java index 5554a9003c..4dbfa3aded 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/BlockIETileProvider.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/BlockIETileProvider.java @@ -178,9 +178,8 @@ else if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) } if(tile instanceof ITileDrop) { - ItemStack s = ((ITileDrop)tile).getTileDrop(harvesters.get(), state); - if(!s.isEmpty()) - drops.add(s); + NonNullList s = ((ITileDrop)tile).getTileDrops(harvesters.get(), state); + drops.addAll(s); } else super.getDrops(drops, world, pos, state, fortune); @@ -231,7 +230,7 @@ public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World wo TileEntity tile = world.getTileEntity(pos); if(tile instanceof ITileDrop) { - ItemStack s = ((ITileDrop)tile).getTileDrop(player, world.getBlockState(pos)); + ItemStack s = ((ITileDrop)tile).getPickBlock(player, world.getBlockState(pos), target); if(!s.isEmpty()) return s; } diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/IEBlockInterfaces.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/IEBlockInterfaces.java index 63d45422e3..8f9adf9452 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/IEBlockInterfaces.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/IEBlockInterfaces.java @@ -23,6 +23,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing.Axis; import net.minecraft.util.EnumHand; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -177,7 +178,24 @@ public interface IConfigurableSides public interface ITileDrop { - ItemStack getTileDrop(@Nullable EntityPlayer player, IBlockState state); + /** + * Don't call this on generic TE'S, use getTileDrops or getPickBlock + */ + default ItemStack getTileDrop(@Nullable EntityPlayer player, IBlockState state) + { + NonNullList drops = getTileDrops(player, state); + return drops.size()>0?drops.get(0):ItemStack.EMPTY; + } + + default NonNullList getTileDrops(@Nullable EntityPlayer player, IBlockState state) + { + return NonNullList.from(ItemStack.EMPTY, getTileDrop(player, state)); + } + + default ItemStack getPickBlock(@Nullable EntityPlayer player, IBlockState state, RayTraceResult rayRes) + { + return getTileDrop(player, state); + } void readOnPlacement(@Nullable EntityLivingBase placer, ItemStack stack); diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/BlockConnector.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/BlockConnector.java index b7da288d20..93c5db2456 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/BlockConnector.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/BlockConnector.java @@ -197,8 +197,7 @@ public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World wo } } } - Item item = Item.getItemFromBlock(this); - return item==Items.AIR?ItemStack.EMPTY: new ItemStack(item, 1, this.damageDropped(world.getBlockState(pos))); + return super.getPickBlock(state, target, world, pos, player); } @Override diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TileEntityFeedthrough.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TileEntityFeedthrough.java index 1ffd78f515..a167968ec5 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TileEntityFeedthrough.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TileEntityFeedthrough.java @@ -20,6 +20,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; @@ -175,24 +176,19 @@ public BlockPos getConnectionMaster(WireType cableType, TargetingInfo target) } @Override - public ItemStack getTileDrop(@Nullable EntityPlayer player, IBlockState state) + public NonNullList getTileDrops(@Nullable EntityPlayer player, IBlockState state) { WireApi.FeedthroughModelInfo info = INFOS.get(reference); if (info.canReplace()) { if (offset==0) + return Utils.getDrops(stateForMiddle); + else { - NonNullList ret = Utils.getDrops(stateForMiddle); - if (ret.size()>0) - { - for (int i = 1;i getDrops(IBlockState state) { - DropBlockAcess w = new DropBlockAcess(state); + IBlockAccess w = getSingleBlockWorldAccess(state); NonNullList ret = NonNullList.create(); state.getBlock().getDrops(ret, w, BlockPos.ORIGIN, state, 0); return ret; @@ -1575,10 +1575,15 @@ private static > IBlockState setProp(IBlockState state, return state; } - private static class DropBlockAcess implements IBlockAccess + public static IBlockAccess getSingleBlockWorldAccess(IBlockState state) + { + return new SingleBlockAcess(state); + } + + private static class SingleBlockAcess implements IBlockAccess { IBlockState state; - public DropBlockAcess(IBlockState state) { + public SingleBlockAcess(IBlockState state) { this.state = state; }