From 5c56adaeaa87151d13085038baab982470cefb43 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 26 Sep 2020 00:59:43 +0200 Subject: [PATCH] Midnight bugs - Fixed deployers not firing any right-click actions - Fixed basin renderer crashing outside of dev env - Fixed some lighting and flickering on psis --- .../PortableStorageInterfaceRenderer.java | 2 +- .../PortableStorageInterfaceTileEntity.java | 2 +- .../components/deployer/DeployerHandler.java | 53 +++++++++++-------- .../train/MinecartTrain.java | 18 +++++++ .../IItemHandlerModifiableIntermediate.java | 15 ++++++ .../foundation/item/SmartInventory.java | 13 ++++- 6 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/item/IItemHandlerModifiableIntermediate.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java index d3f869473..9efa6b692 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java @@ -33,7 +33,7 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer sbb.renderInto(ms, vb), ms); + render(blockState, progress, te.isConnected(), sbb -> sbb.light(light).renderInto(ms, vb), ms); } public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java index 7fc799514..9c5e3abcd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java @@ -95,7 +95,7 @@ public class PortableStorageInterfaceTileEntity extends SmartTileEntity { boolean isConnected() { int timeUnit = getTransferTimeout() / 2; - return transferTimer >= timeUnit && transferTimer < timeUnit * 3; + return transferTimer >= timeUnit && transferTimer <= timeUnit * 3; } float getExtensionDistance(float partialTicks) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerHandler.java index 0ee36f6df..5dfceef48 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerHandler.java @@ -6,16 +6,6 @@ import static net.minecraftforge.eventbus.api.Event.Result.DENY; import java.util.ArrayList; import java.util.List; -import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.block.BeehiveBlock; -import net.minecraft.block.Block; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.Enchantments; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.server.management.PlayerInteractionManager; -import net.minecraft.stats.Stats; -import net.minecraft.tileentity.BeehiveTileEntity; -import net.minecraft.tileentity.TileEntity; import org.apache.commons.lang3.tuple.Pair; import com.google.common.collect.Multimap; @@ -23,14 +13,20 @@ import com.simibubi.create.content.contraptions.components.deployer.DeployerTile import com.simibubi.create.content.curiosities.tools.SandPaperItem; import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.block.BeehiveBlock; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.material.Material; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.minecraft.inventory.EquipmentSlotType; @@ -43,6 +39,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; +import net.minecraft.server.management.PlayerInteractionManager; +import net.minecraft.stats.Stats; +import net.minecraft.tileentity.BeehiveTileEntity; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; @@ -95,7 +95,8 @@ public class DeployerHandler { static boolean shouldActivate(ItemStack held, World world, BlockPos targetPos) { if (held.getItem() instanceof BlockItem) - if (world.getBlockState(targetPos).getBlock() == ((BlockItem) held.getItem()).getBlock()) + if (world.getBlockState(targetPos) + .getBlock() == ((BlockItem) held.getItem()).getBlock()) return false; if (held.getItem() instanceof BucketItem) { @@ -155,7 +156,8 @@ public class DeployerHandler { } if (!success && stack.isFood() && entity instanceof PlayerEntity) { PlayerEntity playerEntity = (PlayerEntity) entity; - if (playerEntity.canEat(item.getFood().canEatWhenFull())) { + if (playerEntity.canEat(item.getFood() + .canEatWhenFull())) { playerEntity.onFoodEaten(world, stack); player.spawnedItemEffects = stack.copy(); success = true; @@ -254,8 +256,11 @@ public class DeployerHandler { boolean flag1 = !(player.isSneaking() && holdingSomething) || (stack.doesSneakBypassUse(world, clickedPos, player)); + if (clickedState.getBlock() instanceof BeehiveBlock) + return; // Beehives assume a lot about the usage context. Crashes to side-effects + // Use on block - if (useBlock != DENY && flag1 && clickedState.getBlock() instanceof BeehiveBlock && clickedState.onUse(world, player, hand, result) == ActionResultType.SUCCESS) + if (useBlock != DENY && flag1 && clickedState.onUse(world, player, hand, result) == ActionResultType.SUCCESS) return; if (stack.isEmpty()) return; @@ -304,7 +309,7 @@ public class DeployerHandler { private static boolean safeTryHarvestBlock(PlayerInteractionManager interactionManager, BlockPos clickedPos) { BlockState state = interactionManager.world.getBlockState(clickedPos); - if(!(state.getBlock() instanceof BeehiveBlock)) + if (!(state.getBlock() instanceof BeehiveBlock)) return interactionManager.tryHarvestBlock(clickedPos); else { harvestBeehive(interactionManager, state, clickedPos); @@ -312,19 +317,24 @@ public class DeployerHandler { return true; } - private static void harvestBeehive(PlayerInteractionManager interactionManager, BlockState state, BlockPos clickedPos) { - // Modified code from PlayerInteractionManager, Block and BeehiveBlock to handle deployers breaking beehives without crash. + private static void harvestBeehive(PlayerInteractionManager interactionManager, BlockState state, + BlockPos clickedPos) { + // Modified code from PlayerInteractionManager, Block and BeehiveBlock to handle + // deployers breaking beehives without crash. ItemStack itemstack = interactionManager.player.getHeldItemMainhand(); ItemStack itemstack1 = itemstack.copy(); boolean flag1 = state.canHarvestBlock(interactionManager.world, clickedPos, interactionManager.player); itemstack.onBlockDestroyed(interactionManager.world, state, clickedPos, interactionManager.player); if (itemstack.isEmpty() && !itemstack1.isEmpty()) - net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(interactionManager.player, itemstack1, Hand.MAIN_HAND); + net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(interactionManager.player, itemstack1, + Hand.MAIN_HAND); - boolean flag = state.removedByPlayer(interactionManager.world, clickedPos, interactionManager.player, flag1, interactionManager.world.getFluidState(clickedPos)); + boolean flag = state.removedByPlayer(interactionManager.world, clickedPos, interactionManager.player, flag1, + interactionManager.world.getFluidState(clickedPos)); if (flag) - state.getBlock().onPlayerDestroy(interactionManager.world, clickedPos, state); + state.getBlock() + .onPlayerDestroy(interactionManager.world, clickedPos, state); if (flag && flag1) { interactionManager.player.addStat(Stats.BLOCK_MINED.get(state.getBlock())); @@ -334,12 +344,13 @@ public class DeployerHandler { Block.spawnDrops(state, interactionManager.world, clickedPos, te, interactionManager.player, heldItem); if (!interactionManager.world.isRemote && te instanceof BeehiveTileEntity) { - BeehiveTileEntity beehivetileentity = (BeehiveTileEntity)te; + BeehiveTileEntity beehivetileentity = (BeehiveTileEntity) te; if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, heldItem) == 0) { interactionManager.world.updateComparatorOutputLevel(clickedPos, state.getBlock()); } - CriteriaTriggers.BEE_NEST_DESTROYED.test((ServerPlayerEntity)interactionManager.player, state.getBlock(), heldItem, beehivetileentity.getBeeCount()); + CriteriaTriggers.BEE_NEST_DESTROYED.test((ServerPlayerEntity) interactionManager.player, + state.getBlock(), heldItem, beehivetileentity.getBeeCount()); } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartTrain.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartTrain.java index 987e73920..9390bed32 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartTrain.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartTrain.java @@ -2,9 +2,11 @@ package com.simibubi.create.content.contraptions.components.structureMovement.tr import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.UUID; import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntity; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.Iterate; @@ -55,6 +57,8 @@ public class MinecartTrain { // SOFT collision - modify motion of carts with stressed links @t+1 double sharedMotion = 0; int participants = 0; + boolean stall = false; + for (int i = 0; i < couplings.size(); i++) { MinecartCoupling minecartCoupling = couplings.get(i); boolean last = i + 1 == couplings.size(); @@ -64,6 +68,14 @@ public class MinecartTrain { sharedMotion += minecartCoupling.mainCart.get() .getMotion() .length(); + + List passengers = minecartCoupling.mainCart.get().getPassengers(); + if (!passengers.isEmpty() && passengers.get(0) instanceof ContraptionEntity) + if (((ContraptionEntity) passengers.get(0)).isStalled()) { + stall = true; + break; + } + if (last) { participants++; @@ -137,6 +149,12 @@ public class MinecartTrain { MinecartCoupling minecartCoupling = couplings.get(i); if (!minecartCoupling.areBothEndsPresent()) continue; + + if (stall) { + minecartCoupling.asCouple().forEach(ame -> ame.setMotion(Vec3d.ZERO)); + continue; + } + double stress = getStressOfCoupling(minecartCoupling); if (stress > maxStress) { maxStress = stress; diff --git a/src/main/java/com/simibubi/create/foundation/item/IItemHandlerModifiableIntermediate.java b/src/main/java/com/simibubi/create/foundation/item/IItemHandlerModifiableIntermediate.java new file mode 100644 index 000000000..9e035eb1f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/item/IItemHandlerModifiableIntermediate.java @@ -0,0 +1,15 @@ +package com.simibubi.create.foundation.item; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandlerModifiable; + +interface IItemHandlerModifiableIntermediate extends IItemHandlerModifiable { + + @Override + public default ItemStack getStackInSlot(int slot) { + return getStackInSlotIntermediate(slot); + } + + public ItemStack getStackInSlotIntermediate(int slot); + +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java b/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java index 71ddba451..7e5050848 100644 --- a/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java +++ b/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java @@ -7,11 +7,10 @@ import com.simibubi.create.foundation.tileEntity.SyncedTileEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraftforge.common.util.INBTSerializable; -import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.wrapper.RecipeWrapper; -public class SmartInventory extends RecipeWrapper implements IItemHandlerModifiable, INBTSerializable { +public class SmartInventory extends RecipeWrapper implements IItemHandlerModifiableIntermediate, INBTSerializable { private boolean extractionAllowed; private boolean insertionAllowed; @@ -83,6 +82,11 @@ public class SmartInventory extends RecipeWrapper implements IItemHandlerModifia inv.setStackInSlot(slot, stack); } + @Override + public ItemStack getStackInSlot(int slot) { + return super.getStackInSlot(slot); + } + public int getStackLimit(int slot, @Nonnull ItemStack stack) { return Math.min(getSlotLimit(slot), stack.getMaxStackSize()); } @@ -118,4 +122,9 @@ public class SmartInventory extends RecipeWrapper implements IItemHandlerModifia } + @Override + public ItemStack getStackInSlotIntermediate(int slot) { + return getStackInSlot(slot); + } + }