From 80b3d7b64f41c0ff7a1e0c2009bb97b3a4f96250 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:36:31 -0600 Subject: [PATCH] Just display stand things... --- .../mod/blocks/ActuallyBlocks.java | 4 +- .../mod/blocks/BlockDisplayStand.java | 55 +++++++----- .../mod/blocks/BlockEmpowerer.java | 87 ------------------- .../blocks/render/ReconstructorRenderer.java | 1 + .../mod/blocks/render/RenderDisplayStand.java | 5 +- .../mod/blocks/render/RenderEmpowerer.java | 5 +- .../actuallyadditions/mod/util/AssetUtil.java | 20 +++++ 7 files changed, 64 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java index cc403b8aa..e46ac97df 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java @@ -152,9 +152,9 @@ public final class ActuallyBlocks { public static final AABlockReg LAMP_BLACK = new AABlockReg<>("lamp_black", BlockColoredLamp::new, (b) -> new AABlockItem(b, defaultBlockItemProperties)); // Empowerer / Display Stands - public static final AABlockReg EMPOWERER = new AABlockReg<>("empowerer", BlockEmpowerer::new, + public static final AABlockReg EMPOWERER = new AABlockReg<>("empowerer", () -> new BlockDisplayStand(true), (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityEmpowerer::new); - public static final AABlockReg DISPLAY_STAND = new AABlockReg<>("display_stand", BlockDisplayStand::new, + public static final AABlockReg DISPLAY_STAND = new AABlockReg<>("display_stand", () -> new BlockDisplayStand(false), (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityDisplayStand::new); // Interface Blocks diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDisplayStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDisplayStand.java index 00423a546..fe1108ac0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockDisplayStand.java @@ -12,6 +12,8 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityEmpowerer; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.block.BlockState; @@ -31,47 +33,60 @@ import javax.annotation.Nullable; public class BlockDisplayStand extends BlockContainerBase { - public BlockDisplayStand() { + public BlockDisplayStand(boolean empowerer) { super(ActuallyBlocks.defaultPickProps(0)); + isEmpowerer = empowerer; + } + + private final boolean isEmpowerer; + + public boolean isEmpowerer() { + return this.isEmpowerer; } @Nullable - //@Override - public TileEntity newBlockEntity(IBlockReader worldIn) { - return new TileEntityDisplayStand(); + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) { + return isEmpowerer? new TileEntityEmpowerer(): new TileEntityDisplayStand(); + } + + @Override + public boolean hasTileEntity(BlockState state) { + return true; } @Override public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { ItemStack heldItem = player.getItemInHand(hand); if (!world.isClientSide) { - TileEntityDisplayStand stand = (TileEntityDisplayStand) world.getBlockEntity(pos); + TileEntityInventoryBase stand = (TileEntityInventoryBase) world.getBlockEntity(pos); if (stand != null) { - ItemStack display = stand.inv.getStackInSlot(0); - if (StackUtil.isValid(heldItem)) { - if (!StackUtil.isValid(display)) { + ItemStack stackThere = stand.inv.getStackInSlot(0); + if (!heldItem.isEmpty()) { + if (stackThere.isEmpty() && (!isEmpowerer || TileEntityEmpowerer.isPossibleInput(heldItem))) { ItemStack toPut = heldItem.copy(); toPut.setCount(1); stand.inv.setStackInSlot(0, toPut); if (!player.isCreative()) { heldItem.shrink(1); } - return ActionResultType.PASS; - } else if (ItemUtil.canBeStacked(heldItem, display)) { - int maxTransfer = Math.min(display.getCount(), heldItem.getMaxStackSize() - heldItem.getCount()); + return ActionResultType.CONSUME; + } else if (ItemUtil.canBeStacked(heldItem, stackThere)) { + int maxTransfer = Math.min(stackThere.getCount(), heldItem.getMaxStackSize() - heldItem.getCount()); if (maxTransfer > 0) { - heldItem.grow(maxTransfer); - ItemStack newDisplay = display.copy(); - newDisplay.shrink(maxTransfer); - stand.inv.setStackInSlot(0, newDisplay); - return ActionResultType.PASS; + if (!player.isCreative()) + player.setItemInHand(hand, StackUtil.grow(heldItem, maxTransfer)); + ItemStack newStackThere = stackThere.copy(); + newStackThere.shrink(maxTransfer); + stand.inv.setStackInSlot(0, newStackThere); + return ActionResultType.CONSUME; } } } else { - if (StackUtil.isValid(display)) { - player.setItemInHand(hand, display.copy()); - stand.inv.setStackInSlot(0, StackUtil.getEmpty()); - return ActionResultType.PASS; + if (!stackThere.isEmpty() && hand == Hand.MAIN_HAND) { + player.setItemInHand(hand, stackThere.copy()); + stand.inv.setStackInSlot(0, ItemStack.EMPTY); + return ActionResultType.CONSUME; } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java deleted file mode 100644 index 117228043..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file ("BlockEmpowerer.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2017 Ellpeck - */ - -package de.ellpeck.actuallyadditions.mod.blocks; - -import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; -import de.ellpeck.actuallyadditions.mod.tile.TileEntityEmpowerer; -import de.ellpeck.actuallyadditions.mod.util.ItemUtil; -import de.ellpeck.actuallyadditions.mod.util.StackUtil; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.World; - -import javax.annotation.Nullable; - -public class BlockEmpowerer extends BlockContainerBase { - public BlockEmpowerer() { - super(ActuallyBlocks.defaultPickProps(0)); - } - - @Nullable - //@Override - public TileEntity newBlockEntity(IBlockReader worldIn) { - return new TileEntityEmpowerer(); - } - - @Override - public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { - ItemStack heldItem = player.getItemInHand(hand); - if (!world.isClientSide) { - TileEntityEmpowerer empowerer = (TileEntityEmpowerer) world.getBlockEntity(pos); - if (empowerer != null) { - ItemStack stackThere = empowerer.inv.getStackInSlot(0); - if (StackUtil.isValid(heldItem)) { - if (!StackUtil.isValid(stackThere) && TileEntityEmpowerer.isPossibleInput(heldItem)) { - ItemStack toPut = heldItem.copy(); - toPut.setCount(1); - empowerer.inv.setStackInSlot(0, toPut); - if (!player.isCreative()) { - heldItem.shrink(1); - } - return ActionResultType.PASS; - } else if (ItemUtil.canBeStacked(heldItem, stackThere)) { - int maxTransfer = Math.min(stackThere.getCount(), heldItem.getMaxStackSize() - heldItem.getCount()); - if (maxTransfer > 0) { - player.setItemInHand(hand, StackUtil.grow(heldItem, maxTransfer)); - ItemStack newStackThere = stackThere.copy(); - newStackThere = StackUtil.shrink(newStackThere, maxTransfer); - empowerer.inv.setStackInSlot(0, newStackThere); - return ActionResultType.PASS; - } - } - } else { - if (StackUtil.isValid(stackThere)) { - player.setItemInHand(hand, stackThere.copy()); - empowerer.inv.setStackInSlot(0, StackUtil.getEmpty()); - return ActionResultType.PASS; - } - } - } - return ActionResultType.FAIL; - } - - return ActionResultType.PASS; - } - - @Override - public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return Shapes.EMPOWERER_SHAPE; - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java index b0f0c08b4..5eeb37ec9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java @@ -23,6 +23,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.item.ItemStack; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.vector.Quaternion; public class ReconstructorRenderer extends TileEntityRenderer { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderDisplayStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderDisplayStand.java index 153f4d8fc..a96c1fcf5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderDisplayStand.java @@ -22,6 +22,7 @@ import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.util.Util; import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; public class RenderDisplayStand extends TileEntityRenderer { public RenderDisplayStand(TileEntityRendererDispatcher rendererDispatcherIn) { @@ -38,9 +39,9 @@ public class RenderDisplayStand extends TileEntityRenderer { public RenderEmpowerer(TileEntityRendererDispatcher rendererDispatcherIn) { @@ -40,9 +41,9 @@ public class RenderEmpowerer extends TileEntityRenderer { matrices.pushPose(); matrices.translate(0.5F, 1F, 0.5F); - double boop = Util.getMillis() / 800D; + float boop = Util.getMillis() / 800F; matrices.translate(0D, Math.sin(boop % (2 * Math.PI)) * 0.065, 0D); - matrices.mulPose(new Quaternion((float) (boop * 40D % 360), 0, 1, 0)); // TODO: [port] might not work + matrices.mulPose(Vector3f.YP.rotationDegrees(boop * 40F % 360.0F)); float scale = stack.getItem() instanceof BlockItem ? 0.85F diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java index fe3399fd3..15189d631 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java @@ -32,6 +32,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.IParticleData; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix4f; @@ -421,6 +422,25 @@ public final class AssetUtil { GlStateManager._popMatrix(); } + @OnlyIn(Dist.CLIENT) + public static void renderTextInWorld(MatrixStack matrixStack, double offsetX, double offsetY, double offsetZ, NonNullList text, int color) { + matrixStack.pushPose(); + matrixStack.translate(offsetX,offsetY,offsetZ); + matrixStack.scale(-1, -1, 1); + matrixStack.mulPose(Vector3f.YP.rotationDegrees(Minecraft.getInstance().cameraEntity.yRot)); + matrixStack.scale(0.01F, 0.01F, 0.01F); + + FontRenderer font = Minecraft.getInstance().font; + + int y = 0; + for (String s : text) { + font.draw(matrixStack, s, 0, y, color); + y+= 10; + } + + matrixStack.popPose(); + } + public static float[] getWheelColor(float pos) { if (pos < 85.0f) { return new float[]{pos * 3.0F, 255.0f - pos * 3.0f, 0.0f};