Jump to content

Recommended Posts

Posted

Hey guys, I'm confused. I'm trying to add a model to my mod (which I've done before successfully) and when placing it places an empty block ( or null according to the debug f3 stuff) instead of the model. I've no idea what's going on because the model renders in the hand of the player fine. So here's the codes.

Block Electric Furnace

package com.euan.newage.tech.blocks;

import java.util.Random;

import com.euan.newage.tech.Main;
import com.euan.newage.tech.blocks.entities.TileEntityElectricFurnace;
import com.euan.newage.tech.util.Reference;

import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class BlockElectricFurnace extends BlockTileEntity<TileEntityElectricFurnace> {
	
	public static final PropertyDirection FACING = BlockHorizontal.FACING;
	public static final PropertyBool BURNING = PropertyBool.create("burning");
	
	public BlockElectricFurnace() {
		super(Material.ROCK, "machine_electric_furnace", Main.mainTab, "machineElectricFurnace");
		setSoundType(SoundType.METAL);
		this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false));
	}
	
	@Override
	public Item getItemDropped(IBlockState state, Random rand, int fortune) {
		return Item.getItemFromBlock(ModBlocks.electricFurnace);
	}
	
	@Override
	public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
		return new ItemStack(ModBlocks.electricFurnace);
	}
	
	@SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }
	
	@Override
    @SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
        return false;
    }
	
	@Override
	public boolean isNormalCube(IBlockState state) {
		return false;
	}
	
	@Override
	public boolean isOpaqueCube(IBlockState state) {
		return false;
	}
	
	@Override
	public TileEntityElectricFurnace createTileEntity(World world, IBlockState state) {
		return new TileEntityElectricFurnace();
	}
	
	@Override
	public Class<TileEntityElectricFurnace> getTileEntityClass() {
		return TileEntityElectricFurnace.class;
	}
	
	@Override
	public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
		if (!world.isRemote) {
			player.openGui(Main.instance, Reference.GUI_ELECTRIC_FURNACE, world, pos.getX(), pos.getY(), pos.getZ());
		}
		return true;
	}
	
	@Override
	public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) 
	{
		if (!worldIn.isRemote) 
        {
            IBlockState north = worldIn.getBlockState(pos.north());
            IBlockState south = worldIn.getBlockState(pos.south());
            IBlockState west = worldIn.getBlockState(pos.west());
            IBlockState east = worldIn.getBlockState(pos.east());
            EnumFacing face = (EnumFacing)state.getValue(FACING);

            if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
            else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
            else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
            else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
            worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
        }
	}


	public static void setState(boolean active, World worldIn, BlockPos pos) 
	{
		IBlockState state = worldIn.getBlockState(pos);
		TileEntity tileentity = worldIn.getTileEntity(pos);
		
		if(active) worldIn.setBlockState(pos, ModBlocks.electricFurnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, true), 3);
		else worldIn.setBlockState(pos, ModBlocks.electricFurnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, false), 3);
		
		if(tileentity != null) 
		{
			tileentity.validate();
			worldIn.setTileEntity(pos, tileentity);
		}
	}

	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) 
	{
		return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
	}

	@Override
	public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
			ItemStack stack) {
		worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
	}

	@Override
	public EnumBlockRenderType getRenderType(IBlockState state) {
		return EnumBlockRenderType.MODEL;
	}

	@Override
	public IBlockState withRotation(IBlockState state, Rotation rot) {
		return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
	}

	@Override
	public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
		return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
	}

	@Override
	protected BlockStateContainer createBlockState() 
	{
		return new BlockStateContainer(this, new IProperty[] {BURNING,FACING});
	}

	@Override
	public IBlockState getStateFromMeta(int meta) 
	{
		EnumFacing facing = EnumFacing.getFront(meta);
		if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
		return this.getDefaultState().withProperty(FACING, facing);
	}
	
	@Override
	public int getMetaFromState(IBlockState state) 
	{
		return ((EnumFacing)state.getValue(FACING)).getIndex();
	}	

	@Override
	public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
		TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityElectricFurnace)
        {
        	TileEntityElectricFurnace te = (TileEntityElectricFurnace)tileentity;
            InventoryHelper.dropInventoryItems(worldIn, pos, te.getIInventory());
            worldIn.updateComparatorOutputLevel(pos, this);
        }
	}
}

 

TileEntityElectricFurnace

package com.euan.newage.tech.blocks.entities;

import java.io.Console;

import javax.annotation.Nullable;
import javax.swing.plaf.basic.BasicComboBoxUI.ItemHandler;

import com.euan.newage.tech.blocks.BlockElectricFurnace;
import com.euan.newage.tech.blocks.BlockHydraulicPress;
import com.euan.newage.tech.items.ModItems;
import com.euan.newage.tech.util.recipes.HydraulicPressRecipes;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TileEntityElectricFurnace extends TileEntity implements ITickable {

	public ItemStackHandler handler = new ItemStackHandler(2);

	private int currentBurningTime;
	private int burningTime = 200;
	private boolean isBurning = false;

	@Override
	public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
			return true;
		else
			return false;
	}

	@Override
	public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
			return (T) this.handler;
		return super.getCapability(capability, facing);
	}

	@Override
	public ITextComponent getDisplayName() {
		return new TextComponentTranslation("tile.machine_electric_furnace");
	}

	@Override
	public void readFromNBT(NBTTagCompound compound) {
		super.readFromNBT(compound);
		this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
		this.currentBurningTime = compound.getInteger("CurrentBurningTime");
		this.burningTime = compound.getInteger("BurningTime");
		this.isBurning = compound.getBoolean("isBurning");

	}

	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
		super.writeToNBT(compound);
		compound.setInteger("CurrentBurningTime", (short) this.currentBurningTime);
		compound.setInteger("BurningTime", (short) this.burningTime);
		compound.setTag("Inventory", this.handler.serializeNBT());
		compound.setBoolean("isBurning", isBurning);

		return compound;
	}

	@Override
	public void update() {
		ItemStack enter = this.handler.getStackInSlot(0);

		if (enter.isEmpty()) {
			stopBurning();
			return;
		}

		ItemStack result = this.handler.getStackInSlot(1);
		ItemStack enterRe = new ItemStack(enter.getItem());
		enterRe.setCount(1);
		enterRe = HydraulicPressRecipes.getInstance().getResult(enterRe);

		if (enterRe.equals(ItemStack.EMPTY) || (result.isEmpty() == false && sameItem(enterRe, result) == false)) {
			stopBurning();
			return;
		}

		if(!canAddToStack(result, enterRe)) {
			stopBurning();
			return;
		}
		
		if (currentBurningTime >= burningTime) {
			if (result.isEmpty()) {
				this.handler.setStackInSlot(1, enterRe);
			} else {
				int count = this.handler.getStackInSlot(1).getCount() + enterRe.getCount();
				this.handler.getStackInSlot(1).setCount(count);
			}
			this.handler.getStackInSlot(0).setCount(this.handler.getStackInSlot(0).getCount() - 1);
			stopBurning();
			return;
		}

		if (isBurning == false && currentBurningTime == 0) {
			if (!enterRe.equals(ItemStack.EMPTY)) {
				startBurning();
			}
		}

		currentBurningTime++;
	}

	private void startBurning() {
		isBurning = true;
		BlockElectricFurnace.setState(isBurning, getWorld(), getPos());
	}

	private void stopBurning() {
		if (isBurning == true) {
			isBurning = false;
			currentBurningTime = 0;
			BlockElectricFurnace.setState(isBurning, getWorld(), getPos());
		}
	}

	public IInventory getIInventory() {
		InventoryBasic basic = new InventoryBasic("", false, 2);
		basic.setInventorySlotContents(0, handler.getStackInSlot(0));
		basic.setInventorySlotContents(1, handler.getStackInSlot(1));
		return basic;
	}
	
	private boolean sameItem(ItemStack itemStack, ItemStack itemStack2) {
		return itemStack.getItem().equals(itemStack2.getItem());
	}

	private boolean canAddToStack(ItemStack itemStack, ItemStack itemStack2) {
		return itemStack.getCount() + itemStack2.getCount() <= itemStack.getMaxStackSize();
	}

	public int getField(int id) {
		switch (id) {
		case 0:
			return burningTime;
		case 1:
			return currentBurningTime;
		default:
			return 0;
		}
	}

	public void setField(int id, int value) {
		switch (id) {
		case 0:
			burningTime = value;
			break;
		case 1:
			currentBurningTime = value;
			break;
		default:
			break;
		}
	}

	public boolean isUsableByPlayer(EntityPlayer player) {
		return this.world.getTileEntity(this.pos) != this ? false
				: player.getDistanceSq((double) this.pos.getX() + 0.5D, (double) this.pos.getY() + 0.5D,
						(double) this.pos.getZ() + 0.5D) <= 64.0D;
	}

}

 

Here's where I'm registering the entity

public static void register(IForgeRegistry<Block> registry) {
		registry.registerAll(oreCopper, oreTin, oreSilver, oreSilicon, oreGarnet, oreSaphire, oreRuby, hydraulicPress);
		GameRegistry.registerTileEntity(hydraulicPress.getTileEntityClass(), hydraulicPress.getRegistryName().toString());
		GameRegistry.registerTileEntity(electricFurnace.getTileEntityClass(), electricFurnace.getRegistryName().toString());
	}
	
	public static void registerItemBlocks(IForgeRegistry<Item> registry) {
		registry.registerAll(oreCopper.createItemBlock(), oreTin.createItemBlock(), oreSilver.createItemBlock(), oreSilicon.createItemBlock(),
				oreGarnet.createItemBlock(), oreSaphire.createItemBlock(), oreRuby.createItemBlock(), hydraulicPress.createItemBlock(),
				electricFurnace.createItemBlock());
	}
	
	public static void registerModels() {
		oreCopper.registerItemModel(Item.getItemFromBlock(oreCopper));
		oreTin.registerItemModel(Item.getItemFromBlock(oreTin));
		oreSilver.registerItemModel(Item.getItemFromBlock(oreSilver));
		oreSilicon.registerItemModel(Item.getItemFromBlock(oreSilicon));
		oreGarnet.registerItemModel(Item.getItemFromBlock(oreGarnet));
		oreSaphire.registerItemModel(Item.getItemFromBlock(oreSaphire));
		oreRuby.registerItemModel(Item.getItemFromBlock(oreRuby));
		hydraulicPress.registerItemModel(Item.getItemFromBlock(hydraulicPress));
		electricFurnace.registerItemModel(Item.getItemFromBlock(electricFurnace));
	}

 

the registerItemModel and createItemBlock methods should be working because they're working for all the other blocks (including the hydraulic press which is another modeled block).

Any ideas?

Posted
3 minutes ago, V0idWa1k3r said:

As far as I can tell you never actually register your 

. You do register it's ItemBlock though.

Thanks man. that was it. Completely forgot to do that :)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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