From 9e2232d24045af46b57162f3c3213e622e67bfe9 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 30 Jun 2020 11:10:24 +0100 Subject: [PATCH 1/2] Clean up entity drop code We were incorrectly using captureDrops directly - it's more reasonable to listen to the drop event. Fixes #486 --- .../shared/util/DropConsumer.java | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java index 47a6915e9..23e40a9d6 100644 --- a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java +++ b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java @@ -13,11 +13,11 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -31,16 +31,16 @@ private DropConsumer() private static Function dropConsumer; private static List remainingDrops; - private static WeakReference dropWorld; + private static World dropWorld; private static AxisAlignedBB dropBounds; - private static WeakReference dropEntity; + private static Entity dropEntity; public static void set( Entity entity, Function consumer ) { dropConsumer = consumer; remainingDrops = new ArrayList<>(); - dropEntity = new WeakReference<>( entity ); - dropWorld = new WeakReference<>( entity.world ); + dropEntity = entity; + dropWorld = entity.world; dropBounds = new AxisAlignedBB( entity.getPosition() ).grow( 2, 2, 2 ); entity.captureDrops = true; @@ -51,26 +51,12 @@ public static void set( World world, BlockPos pos, Function( 2 ); dropEntity = null; - dropWorld = new WeakReference<>( world ); + dropWorld = world; dropBounds = new AxisAlignedBB( pos ).grow( 2, 2, 2 ); } public static List clear() { - if( dropEntity != null ) - { - Entity entity = dropEntity.get(); - if( entity != null ) - { - entity.captureDrops = false; - if( entity.capturedDrops != null ) - { - for( EntityItem entityItem : entity.capturedDrops ) handleDrops( entityItem.getItem() ); - entity.capturedDrops.clear(); - } - } - } - List remainingStacks = remainingDrops; dropConsumer = null; @@ -92,11 +78,20 @@ private static void handleDrops( ItemStack stack ) public static void onEntitySpawn( EntityJoinWorldEvent event ) { // Capture any nearby item spawns - if( dropWorld != null && dropWorld.get() == event.getWorld() && event.getEntity() instanceof EntityItem + if( dropWorld == event.getWorld() && event.getEntity() instanceof EntityItem && dropBounds.contains( event.getEntity().getPositionVector() ) ) { handleDrops( ((EntityItem) event.getEntity()).getItem() ); event.setCanceled( true ); } } + + @SubscribeEvent + public static void onLivingDrops( LivingDropsEvent drops ) + { + if( dropEntity == null || drops.getEntity() != dropEntity ) return; + + for( EntityItem drop : drops.getDrops() ) handleDrops( drop.getItem() ); + drops.setCanceled( true ); + } } From 37a447e745a27b66b670c756e8209d3127fce556 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 30 Jun 2020 11:10:26 +0100 Subject: [PATCH 2/2] Bump version to 1.89.2 Somewhat reluctant to do this, but it's a pretty major bug. --- gradle.properties | 2 +- .../resources/assets/computercraft/lua/rom/help/changelog.txt | 4 ++++ .../resources/assets/computercraft/lua/rom/help/whatsnew.txt | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index f71c4f6e1..9bf4d7b26 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Mod properties -mod_version=1.89.1 +mod_version=1.89.2 # Minecraft properties mc_version=1.12.2 diff --git a/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt b/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt index 97d223b6b..14e625377 100644 --- a/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt +++ b/src/main/resources/assets/computercraft/lua/rom/help/changelog.txt @@ -1,3 +1,7 @@ +# New features in CC: Tweaked 1.89.2 + +* Fix dupe bug when killing an entity with a turtle. + # New features in CC: Tweaked 1.89.1 * Fix crashes when rendering monitors of varying sizes. diff --git a/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt b/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt index ddb0a9fe9..d6718d6b8 100644 --- a/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt +++ b/src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt @@ -1,5 +1,5 @@ -New features in CC: Tweaked 1.89.1 +New features in CC: Tweaked 1.89.2 -* Fix crashes when rendering monitors of varying sizes. +* Fix dupe bug when killing an entity with a turtle. Type "help changelog" to see the full version history.