From 0d9a6cc8c30e92c06ce4c4960ebd10e846d501de Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 24 Nov 2020 16:56:02 +0100 Subject: [PATCH] Tanks of Jank - Fluid tanks now attach the full multiblock when a part of them is moved by a contraption - Fluid tanks now rotate and mirror properly - Fluid tanks now react to movement properly - Creative fluid tanks no longer lose configured fluid when more tanks are added to it - Fluid tanks no longer render ghost fluids when placed with nbt - Fixed some inconsistencies with tanks distributing fluids when connecting/disconnecting in multiblocks - TileEntities are now being considered when rendering static blocks in a moving structure. Fixed brackets and tank blocks not rendering properly - Poles no longer display their length when used for decoration - Increased scope of caught exceptions when rendering modded tes in schematics and on contraptions --- .../BlockMovementTraits.java | 40 +++++++++----- .../structureMovement/Contraption.java | 11 +++- .../ContraptionRenderer.java | 1 + .../glue/SuperGlueEntity.java | 2 +- .../fluids/tank/FluidTankBlock.java | 53 +++++++++++++++++-- .../tank/FluidTankConnectivityHandler.java | 46 +++++++++++----- .../fluids/tank/FluidTankItem.java | 19 +++++++ .../fluids/tank/FluidTankTileEntity.java | 24 ++++++++- .../goggles/GoggleOverlayRenderer.java | 46 ++++++++++------ .../utility/TileEntityRenderHelper.java | 26 ++++----- .../PlacementSimulationWorld.java | 22 ++++++-- 11 files changed, 226 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java index 744444c12..941c91731 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java @@ -19,6 +19,8 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pis import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity; +import com.simibubi.create.content.contraptions.fluids.tank.FluidTankBlock; +import com.simibubi.create.content.contraptions.fluids.tank.FluidTankConnectivityHandler; import com.simibubi.create.content.logistics.block.redstone.RedstoneLinkBlock; import net.minecraft.block.AbstractPressurePlateBlock; @@ -45,6 +47,7 @@ import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockReader; import net.minecraft.world.World; public class BlockMovementTraits { @@ -55,9 +58,11 @@ public class BlockMovementTraits { return true; if (state.getBlock() instanceof FenceGateBlock) return true; - if (state.getMaterial().isReplaceable()) + if (state.getMaterial() + .isReplaceable()) return false; - if (state.getCollisionShape(world, pos).isEmpty()) + if (state.getCollisionShape(world, pos) + .isEmpty()) return false; return true; } @@ -104,7 +109,7 @@ public class BlockMovementTraits { Block block = state.getBlock(); if (state.has(BlockStateProperties.HANGING)) return true; - + if (block instanceof LadderBlock) return true; if (block instanceof TorchBlock) @@ -129,7 +134,8 @@ public class BlockMovementTraits { /** * Attached blocks will move if blocks they are attached to are moved */ - public static boolean isBlockAttachedTowards(BlockState state, Direction direction) { + public static boolean isBlockAttachedTowards(IBlockReader world, BlockPos pos, BlockState state, + Direction direction) { Block block = state.getBlock(); if (block instanceof LadderBlock) return state.get(LadderBlock.FACING) == direction.getOpposite(); @@ -167,23 +173,30 @@ public class BlockMovementTraits { if (block instanceof AbstractRailBlock) return direction == Direction.DOWN; if (block instanceof AttachedActorBlock) - return direction == state.get(HarvesterBlock.HORIZONTAL_FACING).getOpposite(); + return direction == state.get(HarvesterBlock.HORIZONTAL_FACING) + .getOpposite(); if (block instanceof HandCrankBlock) - return direction == state.get(HandCrankBlock.FACING).getOpposite(); + return direction == state.get(HandCrankBlock.FACING) + .getOpposite(); if (block instanceof NozzleBlock) - return direction == state.get(NozzleBlock.FACING).getOpposite(); + return direction == state.get(NozzleBlock.FACING) + .getOpposite(); if (block instanceof EngineBlock) - return direction == state.get(EngineBlock.HORIZONTAL_FACING).getOpposite(); + return direction == state.get(EngineBlock.HORIZONTAL_FACING) + .getOpposite(); if (block instanceof BellBlock) { BellAttachment attachment = state.get(BlockStateProperties.BELL_ATTACHMENT); - if (attachment == BellAttachment.FLOOR) + if (attachment == BellAttachment.FLOOR) return direction == Direction.DOWN; - if (attachment == BellAttachment.CEILING) + if (attachment == BellAttachment.CEILING) return direction == Direction.UP; return direction == state.get(HorizontalBlock.HORIZONTAL_FACING); } if (state.getBlock() instanceof SailBlock) - return direction.getAxis() != state.get(SailBlock.FACING).getAxis(); + return direction.getAxis() != state.get(SailBlock.FACING) + .getAxis(); + if (state.getBlock() instanceof FluidTankBlock) + return FluidTankConnectivityHandler.isConnected(world, pos, pos.offset(direction)); return false; } @@ -209,8 +222,9 @@ public class BlockMovementTraits { if (state.getBlock() instanceof CarpetBlock) return facing == Direction.UP; if (state.getBlock() instanceof SailBlock) - return facing.getAxis() == state.get(SailBlock.FACING).getAxis(); + return facing.getAxis() == state.get(SailBlock.FACING) + .getAxis(); return isBrittle(state); } - + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index f0d5cff5f..0f544f1cc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -39,6 +39,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pul import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity; +import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity; import com.simibubi.create.content.contraptions.relays.belt.BeltBlock; import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateBlock; import com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock; @@ -288,7 +289,7 @@ public abstract class Contraption { boolean wasVisited = visited.contains(offsetPos); boolean faceHasGlue = superglue.containsKey(offset); boolean blockAttachedTowardsFace = - BlockMovementTraits.isBlockAttachedTowards(blockState, offset.getOpposite()); + BlockMovementTraits.isBlockAttachedTowards(world, offsetPos, blockState, offset.getOpposite()); boolean brittle = BlockMovementTraits.isBrittle(blockState); if (!wasVisited && ((isSlimeBlock && !brittle) || blockAttachedTowardsFace || faceHasGlue)) @@ -461,6 +462,11 @@ public abstract class Contraption { nbt.remove("x"); nbt.remove("y"); nbt.remove("z"); + + if (tileentity instanceof FluidTankTileEntity && nbt.contains("Controller")) + nbt.put("Controller", + NBTUtil.writeBlockPos(toLocalPos(NBTUtil.readBlockPos(nbt.getCompound("Controller"))))); + return nbt; } @@ -734,6 +740,9 @@ public abstract class Contraption { tag.remove("InitialOffset"); } + if (tileEntity instanceof FluidTankTileEntity && tag.contains("LastKnownPos")) + tag.put("LastKnownPos", NBTUtil.writeBlockPos(BlockPos.ZERO.down())); + tileEntity.read(tag); if (storage.containsKey(block.pos)) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index 1308d6270..ac1093e1b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -86,6 +86,7 @@ public class ContraptionRenderer { Random random = new Random(); BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + renderWorld.setTileEntities(c.renderedTileEntities); for (BlockInfo info : c.getBlocks().values()) renderWorld.setBlockState(info.pos, info.state); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index 4a197308f..d4a6f9b65 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -176,7 +176,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat public static boolean isValidFace(World world, BlockPos pos, Direction direction) { BlockState state = world.getBlockState(pos); - if (BlockMovementTraits.isBlockAttachedTowards(state, direction)) + if (BlockMovementTraits.isBlockAttachedTowards(world, pos, state, direction)) return true; if (!BlockMovementTraits.movementNecessary(world, pos)) return false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java index c77744f36..7a8346118 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankBlock.java @@ -28,6 +28,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.IStringSerializable; +import net.minecraft.util.Mirror; +import net.minecraft.util.Rotation; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvents; @@ -41,6 +43,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; public class FluidTankBlock extends Block implements IWrenchable, ITE { @@ -72,9 +75,11 @@ public class FluidTankBlock extends Block implements IWrenchable, ITE tankCapability = te.fluidCapability; + LazyOptional tankCapability = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY); if (!tankCapability.isPresent()) return ActionResultType.PASS; IFluidHandler fluidTank = tankCapability.orElse(null); @@ -142,7 +147,8 @@ public class FluidTankBlock extends Block implements IWrenchable, ITE type = te.getType(); World world = te.getWorld(); BlockPos origin = te.getPos(); - FluidStack fluid = te.getTankInventory() - .getFluid(); + LazyOptional capability = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY); + FluidTank teTank = (FluidTank) capability.orElse(null); + FluidStack fluid = capability.map(ifh -> ifh.getFluidInTank(0)) + .orElse(FluidStack.EMPTY); Search: @@ -192,6 +199,8 @@ public class FluidTankConnectivityHandler { if (simulate) return amount; + + boolean opaque = false; for (int yOffset = 0; yOffset < height; yOffset++) { for (int xOffset = 0; xOffset < width; xOffset++) { @@ -201,10 +210,15 @@ public class FluidTankConnectivityHandler { if (tank == te) continue; - if (tank.isController()) { - te.tankInventory.fill(tank.tankInventory.getFluid(), FluidAction.EXECUTE); - tank.tankInventory.setFluid(FluidStack.EMPTY); + opaque |= !tank.window; + FluidTank tankTank = tank.tankInventory; + FluidStack fluidInTank = tankTank.getFluid(); + if (!fluidInTank.isEmpty()) { + if (teTank.isEmpty() && teTank instanceof CreativeSmartFluidTank) + ((CreativeSmartFluidTank) teTank).setContainedFluid(fluidInTank); + teTank.fill(fluidInTank, FluidAction.EXECUTE); } + tankTank.setFluid(FluidStack.EMPTY); splitTankAndInvalidate(tank, cache, false); tank.setController(origin); @@ -220,6 +234,8 @@ public class FluidTankConnectivityHandler { } } } + + te.setWindows(!opaque); return amount; } @@ -243,8 +259,9 @@ public class FluidTankConnectivityHandler { FluidStack toDistribute = te.tankInventory.getFluid() .copy(); int maxCapacity = FluidTankTileEntity.getCapacityMultiplier(); - if (!toDistribute.isEmpty()) + if (!toDistribute.isEmpty() && !te.isRemoved()) toDistribute.shrink(maxCapacity); + te.applyFluidTankSize(1); for (int yOffset = 0; yOffset < height; yOffset++) { for (int xOffset = 0; xOffset < width; xOffset++) { @@ -259,14 +276,19 @@ public class FluidTankConnectivityHandler { continue; FluidTankTileEntity controllerTE = tankAt.getControllerTE(); tankAt.window = controllerTE == null || controllerTE.window; - tankAt.removeController(); + tankAt.removeController(true); if (!toDistribute.isEmpty() && tankAt != te) { - int split = Math.min(maxCapacity, toDistribute.getAmount()); FluidStack copy = toDistribute.copy(); - copy.setAmount(split); - toDistribute.shrink(split); - tankAt.tankInventory.fill(copy, FluidAction.EXECUTE); + FluidTank tankInventory = tankAt.tankInventory; + if (tankInventory.isEmpty() && tankInventory instanceof CreativeSmartFluidTank) + ((CreativeSmartFluidTank) tankInventory).setContainedFluid(toDistribute); + else { + int split = Math.min(maxCapacity, toDistribute.getAmount()); + copy.setAmount(split); + toDistribute.shrink(split); + tankInventory.fill(copy, FluidAction.EXECUTE); + } } if (tryReconnect) { @@ -300,7 +322,7 @@ public class FluidTankConnectivityHandler { return (FluidTankTileEntity) te; return null; } - + @Nullable public static FluidTankTileEntity anyTankAt(IBlockReader world, BlockPos pos) { TileEntity te = world.getTileEntity(pos); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankItem.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankItem.java index 9dfc502dc..d126ac868 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankItem.java @@ -6,6 +6,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -26,6 +28,23 @@ public class FluidTankItem extends BlockItem { return initialResult; } + @Override + protected boolean onBlockPlaced(BlockPos p_195943_1_, World p_195943_2_, PlayerEntity p_195943_3_, + ItemStack p_195943_4_, BlockState p_195943_5_) { + MinecraftServer minecraftserver = p_195943_2_.getServer(); + if (minecraftserver == null) + return false; + CompoundNBT nbt = p_195943_4_.getChildTag("BlockEntityTag"); + if (nbt != null) { + nbt.remove("Luminosity"); + nbt.remove("Size"); + nbt.remove("Height"); + nbt.remove("Controller"); + nbt.remove("LastKnownPos"); + } + return super.onBlockPlaced(p_195943_1_, p_195943_2_, p_195943_3_, p_195943_4_, p_195943_5_); + } + private void tryMultiPlace(BlockItemUseContext ctx) { PlayerEntity player = ctx.getPlayer(); if (player == null) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java index 469a34954..88717fd1a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java @@ -42,6 +42,7 @@ public class FluidTankTileEntity extends SmartTileEntity { protected boolean forceFluidLevelUpdate; protected FluidTank tankInventory; protected BlockPos controller; + protected BlockPos lastKnownPos; protected boolean updateConnectivity; protected boolean window; protected int luminosity; @@ -88,6 +89,14 @@ public class FluidTankTileEntity extends SmartTileEntity { if (syncCooldown == 0 && queuedSync) sendData(); } + + if (lastKnownPos == null) + lastKnownPos = getPos(); + else if (!lastKnownPos.equals(pos) && pos != null) { + onPositionChanged(); + return; + } + if (updateConnectivity) updateConnectivity(); if (fluidLevel != null) @@ -104,6 +113,11 @@ public class FluidTankTileEntity extends SmartTileEntity { sendData(); } + private void onPositionChanged() { + removeController(true); + lastKnownPos = pos; + } + protected void onFluidStackChanged(FluidStack newFluidStack) { if (!hasWorld()) return; @@ -163,11 +177,12 @@ public class FluidTankTileEntity extends SmartTileEntity { forceFluidLevelUpdate = true; } - public void removeController() { + public void removeController(boolean keepFluids) { if (world.isRemote) return; updateConnectivity = true; - applyFluidTankSize(1); + if (!keepFluids) + applyFluidTankSize(1); controller = null; width = 1; height = 1; @@ -292,7 +307,10 @@ public class FluidTankTileEntity extends SmartTileEntity { updateConnectivity = compound.contains("Uninitialized"); luminosity = compound.getInt("Luminosity"); controller = null; + lastKnownPos = null; + if (compound.contains("LastKnownPos")) + lastKnownPos = NBTUtil.readBlockPos(compound.getCompound("LastKnownPos")); if (compound.contains("Controller")) controller = NBTUtil.readBlockPos(compound.getCompound("Controller")); @@ -344,6 +362,8 @@ public class FluidTankTileEntity extends SmartTileEntity { public void write(CompoundNBT compound, boolean clientPacket) { if (updateConnectivity) compound.putBoolean("Uninitialized", true); + if (lastKnownPos != null) + compound.put("LastKnownPos", NBTUtil.writeBlockPos(lastKnownPos)); if (!isController()) compound.put("Controller", NBTUtil.writeBlockPos(controller)); if (isController()) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java index fcab3bcda..8d428ac5e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java @@ -1,13 +1,20 @@ package com.simibubi.create.content.contraptions.goggles; +import static com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation.spacing; + +import java.util.ArrayList; +import java.util.List; + import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; +import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock; import com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock; import com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonPolePlacementHelper; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.Iterate; + import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; @@ -26,15 +33,9 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -import java.util.ArrayList; -import java.util.List; - -import static com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation.spacing; - @EventBusSubscriber(value = Dist.CLIENT) public class GoggleOverlayRenderer { - @SubscribeEvent public static void lookingAtBlocksThroughGogglesShowsTooltip(RenderGameOverlayEvent.Post event) { if (event.getType() != ElementType.HOTBAR) @@ -76,18 +77,26 @@ public class GoggleOverlayRenderer { tooltip.remove(tooltip.size() - 1); } - //break early if goggle or hover returned false when present + // break early if goggle or hover returned false when present if ((hasGoggleInformation && !goggleAddedInformation) && (hasHoveringInformation && !hoverAddedInformation)) return; - //check for piston poles if goggles are worn + // check for piston poles if goggles are worn BlockState state = world.getBlockState(pos); if (wearingGoggles && AllBlocks.PISTON_EXTENSION_POLE.has(state)) { - Direction[] directions = Iterate.directionsInAxis(state.get(PistonExtensionPoleBlock.FACING).getAxis()); + Direction[] directions = Iterate.directionsInAxis(state.get(PistonExtensionPoleBlock.FACING) + .getAxis()); int poles = 1; - for (Direction dir : directions) - poles += PistonPolePlacementHelper.attachedPoles(world, pos, dir); + boolean pistonFound = false; + for (Direction dir : directions) { + int attachedPoles = PistonPolePlacementHelper.attachedPoles(world, pos, dir); + poles += attachedPoles; + pistonFound |= world.getBlockState(pos.offset(dir, attachedPoles + 1)) + .getBlock() instanceof MechanicalPistonBlock; + } + if (!pistonFound) + return; if (!tooltip.isEmpty()) tooltip.add(""); @@ -99,15 +108,22 @@ public class GoggleOverlayRenderer { RenderSystem.pushMatrix(); Screen tooltipScreen = new TooltipScreen(null); - tooltipScreen.init(mc, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); + tooltipScreen.init(mc, mc.getWindow() + .getScaledWidth(), + mc.getWindow() + .getScaledHeight()); int posX = tooltipScreen.width / 2 + AllConfigs.CLIENT.overlayOffsetX.get(); int posY = tooltipScreen.height / 2 + AllConfigs.CLIENT.overlayOffsetY.get(); - //tooltipScreen.renderTooltip(tooltip, tooltipScreen.width / 2, tooltipScreen.height / 2); + // tooltipScreen.renderTooltip(tooltip, tooltipScreen.width / 2, + // tooltipScreen.height / 2); tooltipScreen.renderTooltip(tooltip, posX, posY); ItemStack item = AllItems.GOGGLES.asStack(); - //GuiGameElement.of(item).at(tooltipScreen.width / 2 + 10, tooltipScreen.height / 2 - 16).render(); - GuiGameElement.of(item).at(posX + 10, posY - 16).render(); + // GuiGameElement.of(item).at(tooltipScreen.width / 2 + 10, tooltipScreen.height + // / 2 - 16).render(); + GuiGameElement.of(item) + .at(posX + 10, posY - 16) + .render(); RenderSystem.popMatrix(); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/TileEntityRenderHelper.java index 1f8a3150c..ea9e6e361 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/TileEntityRenderHelper.java @@ -14,20 +14,19 @@ import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.crash.ReportedException; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class TileEntityRenderHelper { - + public static void renderTileEntities(World world, Iterable customRenderTEs, MatrixStack ms, MatrixStack localTransform, IRenderTypeBuffer buffer) { float pt = Minecraft.getInstance() .getRenderPartialTicks(); Matrix4f matrix = localTransform.peek() .getModel(); - + for (Iterator iterator = customRenderTEs.iterator(); iterator.hasNext();) { TileEntity tileEntity = iterator.next(); TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(tileEntity); @@ -49,17 +48,18 @@ public class TileEntityRenderHelper { OverlayTexture.DEFAULT_UV); ms.pop(); - } catch (ReportedException e) { - if (AllConfigs.CLIENT.explainRenderErrors.get()) { - Create.logger.error("TileEntity " + tileEntity.getType() - .getRegistryName() - .toString() + " didn't want to render while moved.\n", e); - } else { - Create.logger.error("TileEntity " + tileEntity.getType() - .getRegistryName() - .toString() + " didn't want to render while moved.\n"); - } + } catch (Exception e) { iterator.remove(); + + String message = "TileEntity " + tileEntity.getType() + .getRegistryName() + .toString() + " didn't want to render while moved.\n"; + if (AllConfigs.CLIENT.explainRenderErrors.get()) { + Create.logger.error(message, e); + continue; + } + + Create.logger.error(message); continue; } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index c01cc95c6..ee209d16f 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -1,21 +1,30 @@ package com.simibubi.create.foundation.utility.worldWrappers; +import java.util.Collection; import java.util.HashMap; import java.util.function.Predicate; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class PlacementSimulationWorld extends WrappedWorld { public HashMap blocksAdded; + public HashMap tesAdded; public PlacementSimulationWorld(World wrapped) { super(wrapped); blocksAdded = new HashMap<>(); + tesAdded = new HashMap<>(); } - + + public void setTileEntities(Collection tileEntities) { + tesAdded.clear(); + tileEntities.forEach(te -> tesAdded.put(te.getPos(), te)); + } + public void clear() { blocksAdded.clear(); } @@ -31,16 +40,21 @@ public class PlacementSimulationWorld extends WrappedWorld { return setBlockState(pos, state, 0); } + @Override + public TileEntity getTileEntity(BlockPos pos) { + return tesAdded.get(pos); + } + @Override public boolean hasBlockState(BlockPos pos, Predicate condition) { return condition.test(getBlockState(pos)); } - + @Override public boolean isBlockPresent(BlockPos pos) { return true; } - + @Override public boolean isAreaLoaded(BlockPos center, int range) { return true; @@ -52,5 +66,5 @@ public class PlacementSimulationWorld extends WrappedWorld { return blocksAdded.get(pos); return Blocks.AIR.getDefaultState(); } - + }