Jump to content

Recommended Posts

Posted

Hello everyone!

So far I couldn't make an animated block with TER. 

I took a look at BeaconTER, ChestTER and EnchantmentTableTER, yet.

Now I tried to make a syntax error in the TER code: I put more GlStateManager#popMatrix() to cause a StackUnderflow and it didn't happen... so I failed to register TER??

 

P.S: I don't wanna use the IntegerProperty to change texture block because I wanna get a greater effect.

 

Main:

package com.olivemod;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.olivemod.blocks.machine.active.flour_mill.FlourMillTE;
import com.olivemod.blocks.machine.active.flour_mill.FlourMillTER;
import com.olivemod.cap.player.thirsty.IThirsty;
import com.olivemod.cap.player.thirsty.Thirsty;
import com.olivemod.cap.player.thirsty.ThirstyProvider;
import com.olivemod.cap.player.thirsty.ThirstyStorage;
import com.olivemod.event.generation.OreGeneration;
import com.olivemod.event.generation.tree.TreeGeneration;
import com.olivemod.event.player.CapThirstyEvent;
import com.olivemod.fluid.Fluids;
import com.olivemod.hud.CapsBar;
import com.olivemod.init.BlockInit;
import com.olivemod.init.ItemInit;
import com.olivemod.items.energyItem.jetpack.JetPack.JetPackEvent;
import com.olivemod.utils.ModContainerTypes;
import com.olivemod.utils.ModTileEntityTypes;
import com.olivemod.utils.Reference.Reference;

import net.minecraft.client.Minecraft;
import net.minecraft.data.ShapedRecipeBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.crafting.ShapedRecipe;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(Reference.MOD_ID)
@Mod.EventBusSubscriber(modid = Reference.MOD_ID, bus = EventBusSubscriber.Bus.MOD)
public class Main
{
	
	public static Main instance;
	
	// Directly reference a log4j logger.
    public static final Logger LOGGER = LogManager.getLogger();
    
   public Main() {
	
	   	LOGGER.debug("Welcome from OliveMod");	   
	   	@SuppressWarnings("unused")
		final ModLoadingContext modLoadingContext = ModLoadingContext.get();
	   
	   	/*
	   	 * @modEventBus register the setup method for modLoading
	   	 * @modEventBus register the initClient method for modLoading
	   	 */
	   	final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
		modEventBus.addListener(this::setup);
		modEventBus.addListener(this::initClient);

		ItemInit.ITEM.register(modEventBus);
		BlockInit.BLOCK.register(modEventBus);
		ModContainerTypes.CONTAINER_TYPE.register(modEventBus);
		ModTileEntityTypes.TILE_ENTITY_TYPE.register(modEventBus);
		Fluids.FLUIDS.register(modEventBus);

		instance = this;
		MinecraftForge.EVENT_BUS.register(this);
		MinecraftForge.EVENT_BUS.register(new CapsBar());
   }
   
	private void setup(final FMLCommonSetupEvent event) {// K9#8016
		
		OreGeneration.oreGeneration();
		TreeGeneration.init();
		CapabilityManager.INSTANCE.register(IThirsty.class, new ThirstyStorage(), Thirsty::new);
		ShapedRecipe.setCraftingSize(5, 5);
	}
	

	
    private void initClient(final FMLClientSetupEvent event){

    	CapsBar.init();
		ClientRegistry.bindTileEntitySpecialRenderer(FlourMillTE.class, new FlourMillTER());
    }
}

 

TER

package com.olivemod.blocks.machine.active.flour_mill;

import java.util.Random;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL11;

import com.mojang.blaze3d.platform.GlStateManager;
import com.olivemod.utils.Reference.Reference;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData;

@OnlyIn(Dist.CLIENT)
public class FlourMillTER extends TileEntityRenderer<FlourMillTE> 
{
	
	// Directly reference a log4j logger.
    public static final Logger LOGGER = LogManager.getLogger();

	public static final FlourMillTER INSTANCE = new FlourMillTER();
	
	private static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation(Reference.MOD_ID, "flour_mill.png");
	private final FlourMillModel model = new FlourMillModel();
	
	@Override
	public void render(FlourMillTE tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage) {

		this.bindTexture(TEXTURE_LOCATION);
		GlStateManager.pushMatrix();
		GlStateManager.translated(x + 7.0f, y , z + 7.0f);
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferBuilder = tessellator.getBuffer();
        bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
        BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher();
        IBakedModel model = dispatcher.getModelForState(tileEntityIn.getBlockState());
        dispatcher.renderBlock(tileEntityIn.getBlockState(), tileEntityIn.getPos(), tileEntityIn.getWorld(), bufferBuilder, new Random(), EmptyModelData.INSTANCE);
        tessellator.draw();
        System.out.println("Tess");
        GlStateManager.popMatrix();
        
        
        //Debug --> GlStateManager#popMatrix
        
        /*
        GlStateManager.popMatrix();
        GlStateManager.popMatrix();
        GlStateManager.popMatrix();
        GlStateManager.popMatrix();
		*/
	}
	
	

	


}

TE

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.model.animation.IAnimationStateMachine;
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();
	}
	
}

 

BlockClass

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) {

		
		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() {
		// TODO Auto-generated method stub
		return BlockRenderLayer.CUTOUT;
	}
	
	@Override
	public BlockRenderType getRenderType(BlockState state) {

		return BlockRenderType.MODEL;
	}
	
	@Override
	public boolean hasTileEntity() {

		return true;
	}
	
	@Override
	public TileEntity createTileEntity(BlockState state, IBlockReader world) {

		return ModTileEntityTypes.FLOUR_MILL_TE.get().create();
	}


}

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.