From 4325cef8dc3087545819322ef9ac64c007126b58 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Thu, 10 Sep 2020 16:33:29 +0200 Subject: [PATCH] split buffering to prevent crashes when the registered ProjectileDispenseBehavior has some weird stuff going on (mod compat) --- .../actors/dispenser/DispenserMovementBehaviour.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/dispenser/DispenserMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/dispenser/DispenserMovementBehaviour.java index 48ddd8cab..19674c065 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/dispenser/DispenserMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/dispenser/DispenserMovementBehaviour.java @@ -20,6 +20,7 @@ import java.util.HashMap; public class DispenserMovementBehaviour extends DropperMovementBehaviour { private static final HashMap MOVED_DISPENSE_ITEM_BEHAVIOURS = new HashMap<>(); + private static final HashMap MOVED_PROJECTILE_DISPENSE_BEHAVIOURS = new HashMap<>(); private static final DispenserLookup BEHAVIOUR_LOOKUP = new DispenserLookup(); public static void gatherMovedDispenseItemBehaviours() { @@ -46,11 +47,16 @@ public class DispenserMovementBehaviour extends DropperMovementBehaviour { ItemStack backup = itemstack.copy(); // If none is there, try vanilla registry try { + if (MOVED_PROJECTILE_DISPENSE_BEHAVIOURS.containsKey(itemstack.getItem())) { + setItemStackAt(location, MOVED_PROJECTILE_DISPENSE_BEHAVIOURS.get(itemstack.getItem()).dispense(itemstack, context, pos), context); + return; + } + IDispenseItemBehavior idispenseitembehavior = BEHAVIOUR_LOOKUP.getBehavior(itemstack); if (idispenseitembehavior instanceof ProjectileDispenseBehavior) { // Projectile behaviours can be converted most of the time IMovedDispenseItemBehaviour iMovedDispenseItemBehaviour = MovedProjectileDispenserBehaviour.of((ProjectileDispenseBehavior) idispenseitembehavior); setItemStackAt(location, iMovedDispenseItemBehaviour.dispense(itemstack, context, pos), context); - registerMovedDispenseItemBehaviour(itemstack.getItem(), iMovedDispenseItemBehaviour); // buffer conversion if successful + MOVED_PROJECTILE_DISPENSE_BEHAVIOURS.put(itemstack.getItem(), iMovedDispenseItemBehaviour); // buffer conversion if successful return; }