Posted August 20, 20205 yr I am trying to make an animated block (flour mill). I made the TE, TER and Model. When i place the block, it is rendered transparent. Achive: When wheat is put inside(with a hopper because it has not any screen) it and the mill (south side of the block) is near water, mill must rotate. Block Class package com.olivemod.blocks.machine.active.flour_mill; import com.olivemod.blocks.machine.active.fluid_transporter.TileEntityFluidTransporter; import com.olivemod.utils.ModTileEntityTypes; import net.minecraft.block.Block; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; import net.minecraft.block.HorizontalBlock; import net.minecraft.block.material.Material; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.StateContainer.Builder; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.Direction; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.common.ToolType; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; public class FlourMill extends HorizontalBlock{ public FlourMill() { super(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0f).harvestLevel(2).harvestTool(ToolType.PICKAXE)); this.setDefaultState(this.getDefaultState().with(HORIZONTAL_FACING, Direction.NORTH)); } @Override public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { if (state != newState) { TileEntity tileEntity = worldIn.getTileEntity(pos); if(tileEntity instanceof FlourMillTE) { final ItemStackHandler inventory = ((FlourMillTE)tileEntity).inventory; for (int i = 0; i < inventory.getSlots(); i++) { InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), inventory.getStackInSlot(i)); } } } super.onReplaced(state, worldIn, pos, newState, isMoving); } @Override public BlockState getStateForPlacement(BlockItemUseContext context) { return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); } @Override public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { final TileEntity tileEntity = worldIn.getTileEntity(pos); if(tileEntity instanceof FlourMillTE) { return ItemHandlerHelper.calcRedstoneFromInventory(((TileEntityFluidTransporter)tileEntity).inventory); } return super.getComparatorInputOverride(blockState, worldIn, pos); } @Override protected void fillStateContainer(Builder<Block, BlockState> builder) { // TODO Auto-generated method stub super.fillStateContainer(builder); builder.add(HORIZONTAL_FACING); } @Override public BlockState rotate(BlockState state, Rotation rot) { return state.with(HORIZONTAL_FACING, state.get(HORIZONTAL_FACING)); } @Override public BlockState mirror(BlockState state, Mirror mirrorIn) { return state.rotate(mirrorIn.toRotation(state.get(HORIZONTAL_FACING))); } @Override public BlockRenderLayer getRenderLayer() { return BlockRenderLayer.CUTOUT; } @Override public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.ENTITYBLOCK_ANIMATED; } @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return ModTileEntityTypes.FLOUR_MILL_TE.get().create(); } } TE class package com.olivemod.blocks.machine.active.flour_mill; import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.olivemod.utils.ModTileEntityTypes; import com.olivemod.utils.Reference.NBTKeys; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.HorizontalBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.fluid.Fluids; import net.minecraft.inventory.Inventory; import net.minecraft.inventory.container.Container; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.LockableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.wrapper.RangedWrapper; public class FlourMillTE extends TileEntity implements ITickableTileEntity{ private final int IN_SLOT = 0; public final ItemStackHandler inventory = new ItemStackHandler(IN_SLOT + 1) { public boolean isItemValid(int slot, ItemStack stack) { return slot == IN_SLOT && stack.getItem() == Items.WHEAT; }; protected void onContentsChanged(int slot) { FlourMillTE.this.markDirty(); }; }; private final LazyOptional<ItemStackHandler> LOInventory = LazyOptional.of( () -> this.inventory); @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return side == Direction.SOUTH ? this.LOInventory.cast() : LazyOptional.empty(); } protected FlourMillTE(TileEntityType<?> typeIn) { super(typeIn); } public FlourMillTE() { super(ModTileEntityTypes.FLOUR_MILL_TE.get()); } @Override public void read(CompoundNBT compound) { // TODO Auto-generated method stub super.read(compound); this.inventory.deserializeNBT(compound); } @Override public CompoundNBT write(CompoundNBT compound) { compound = super.write(compound); compound.put("inventory", this.inventory.serializeNBT()); return compound; } /* * Retrieves packet to send to the client whenever this Tile Entity is re-sinced via World#notifyBlockUpdate. * This packet comes back client-side via (@link #onDataPacket) */ @Nullable public SUpdateTileEntityPacket getUpdatePacket() { final CompoundNBT tag = new CompoundNBT(); //We pass 0 for TileEntityTypesIn because we have a modded TE.See ClientPlayNetHandler#handlerUpdateTileEntity(SUpdateTileEntityPacket) return new SUpdateTileEntityPacket(this.pos, 0, tag); } /* * Get an NBT compount to sync to the client with SPacketChunkData, used to initial loading of the chunk or when many blocks change at once * This compound comes back to the client-side in (@link #handleUpdateTag) * The default implementation ({@link TileEntity#handleUpdateTag}) calls {@link #writeInternal)} * wich doesn't save any of our extra data so we override it to call {@link #write} instead */ @Nonnull public CompoundNBT getUpdateTag() { return this.write(new CompoundNBT()); } /* * Invalidates our Tile Entity */ @Override public void remove() { super.remove(); //We need to invalidate our capability references so that any cached references (by other mod) don't continue to reference our capablities //and try to use them and/or prevent them from being garbage collected LOInventory.invalidate(); } /* * Handle a packet created in (@link #getUpdatePacket()) */ @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { super.onDataPacket(net, pkt); } @Override public void onLoad() { super.onLoad(); } @Override public void tick() { if (!this.inventory.getStackInSlot(IN_SLOT).isEmpty()) { BlockState millState = this.world.getBlockState(getPos().offset(this.getBlockState().get(HorizontalBlock.HORIZONTAL_FACING).getOpposite())); } } @Override public AxisAlignedBB getRenderBoundingBox() { // TODO Auto-generated method stub return super.getRenderBoundingBox(); } } TER package com.olivemod.blocks.machine.active.flour_mill; import com.mojang.blaze3d.platform.GlStateManager; import com.olivemod.utils.Reference.Reference; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; public class FlourMillTER extends TileEntityRenderer<FlourMillTE> { private static final ResourceLocation TEXTURE_FLOUR_MILL = new ResourceLocation(Reference.MOD_ID, "textures/entity/flour_mill.png"); private final FlourMillModel flourMillModel = new FlourMillModel(); private boolean isWorking; @Override public void render(FlourMillTE tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage) { GlStateManager.enableDepthTest(); GlStateManager.depthFunc(512); GlStateManager.depthMask(true); GlStateManager.pushMatrix(); GlStateManager.translatef((float)x , (float)y , (float)z); this.bindTexture(TEXTURE_FLOUR_MILL); this.setLightmapDisabled(true); this.isGlobalRenderer(tileEntityIn); this.setLightmapDisabled(false); GlStateManager.popMatrix(); } } Model package com.olivemod.blocks.machine.active.flour_mill; import net.minecraft.client.renderer.entity.model.EntityModel; import net.minecraft.client.renderer.entity.model.RendererModel; import net.minecraft.client.renderer.model.ModelBox; import net.minecraft.entity.Entity; // Made with Blockbench 3.5.4 // Exported for Minecraft version 1.14 // Paste this class into your mod and generate all required imports public class FlourMillModel extends EntityModel { private final RendererModel wall; private final RendererModel mill; private final RendererModel stone; private final RendererModel water_mill; public FlourMillModel() { textureWidth = 64; textureHeight = 64; wall = new RendererModel(this); wall.setRotationPoint(0.0F, 24.0F, 0.0F); wall.cubeList.add(new ModelBox(wall, 0, 40, -4.0F, -16.0F, -8.0F, 8, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -4.0F, -16.0F, 7.0F, 8, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 7.0F, -16.0F, -4.0F, 1, 16, 8, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -8.0F, -6.0F, -4.0F, 1, 6, 8, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -8.0F, -16.0F, -4.0F, 1, 6, 8, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -10.0F, -10.0F, -4.0F, 3, 4, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -10.0F, -10.0F, 3.0F, 3, 4, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -11.0F, -10.0F, 2.0F, 1, 4, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -11.0F, -10.0F, -3.0F, 1, 4, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -11.0F, -6.0F, -3.0F, 3, 1, 6, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 6.0F, -16.0F, -5.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 5.0F, -16.0F, -6.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 4.0F, -16.0F, -7.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 4.0F, -16.0F, 6.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -7.0F, -16.0F, -5.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 5.0F, -16.0F, 5.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -6.0F, -16.0F, -6.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 6.0F, -16.0F, 4.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -5.0F, -16.0F, -7.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -7.0F, -16.0F, 4.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -6.0F, -16.0F, 5.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -5.0F, -16.0F, 6.0F, 1, 16, 1, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -4.0F, 0.0F, -7.0F, 8, 0, 14, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 6.0F, 0.0F, -4.0F, 1, 0, 8, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -7.0F, 0.0F, -4.0F, 1, 0, 8, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 5.0F, 0.0F, -5.0F, 1, 0, 10, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -6.0F, 0.0F, -5.0F, 1, 0, 10, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, 4.0F, 0.0F, -6.0F, 1, 0, 12, 0.0F, false)); wall.cubeList.add(new ModelBox(wall, 0, 40, -5.0F, 0.0F, -6.0F, 1, 0, 12, 0.0F, false)); mill = new RendererModel(this); mill.setRotationPoint(0.0F, 24.0F, 0.0F); mill.cubeList.add(new ModelBox(mill, 0, 0, -1.0F, -28.0F, -1.0F, 2, 18, 2, 0.0F, false)); mill.cubeList.add(new ModelBox(mill, 0, 0, -1.0F, -24.0F, 1.0F, 2, 2, 2, 0.0F, false)); mill.cubeList.add(new ModelBox(mill, 0, 0, -1.0F, -24.0F, -3.0F, 2, 2, 2, 0.0F, false)); mill.cubeList.add(new ModelBox(mill, 0, 0, -3.0F, -24.0F, -1.0F, 2, 2, 2, 0.0F, false)); mill.cubeList.add(new ModelBox(mill, 0, 0, 1.0F, -24.0F, -1.0F, 2, 2, 2, 0.0F, false)); stone = new RendererModel(this); stone.setRotationPoint(0.0F, -20.0F, 0.0F); mill.addChild(stone); stone.cubeList.add(new ModelBox(stone, 34, 11, -3.0F, -8.0F, 3.0F, 6, 16, 2, 0.0F, false)); stone.cubeList.add(new ModelBox(stone, 34, 11, -3.0F, -8.0F, -5.0F, 6, 16, 2, 0.0F, false)); stone.cubeList.add(new ModelBox(stone, 34, 11, 3.0F, -8.0F, -3.0F, 2, 16, 6, 0.0F, false)); stone.cubeList.add(new ModelBox(stone, 34, 11, -5.0F, -8.0F, -3.0F, 2, 16, 6, 0.0F, false)); water_mill = new RendererModel(this); water_mill.setRotationPoint(0.0F, 15.0F, -11.0F); water_mill.cubeList.add(new ModelBox(water_mill, 0, 0, 1.0F, -1.0F, -1.0F, 6, 2, 1, 0.0F, false)); water_mill.cubeList.add(new ModelBox(water_mill, 0, 1, -1.0F, -7.0F, -1.0F, 2, 6, 1, 0.0F, false)); water_mill.cubeList.add(new ModelBox(water_mill, 0, 1, -1.0F, 1.0F, -1.0F, 2, 6, 1, 0.0F, false)); water_mill.cubeList.add(new ModelBox(water_mill, 0, 0, -1.0F, -1.0F, -1.0F, 2, 2, 13, 0.0F, false)); water_mill.cubeList.add(new ModelBox(water_mill, 0, 0, -7.0F, -1.0F, -1.0F, 6, 2, 1, 0.0F, false)); } @Override public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { wall.render(f5); mill.render(f5); water_mill.render(f5); } public void setRotationAngle(RendererModel modelRenderer, float x, float y, float z) { modelRenderer.rotateAngleX = x; modelRenderer.rotateAngleY = y; modelRenderer.rotateAngleZ = z; } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.