Jump to content

Recommended Posts

Posted

Hello everyone.

 

So, I have another problem, I am making a machine class for my mod, this class will have all the generic methods that all my machines will have, one of which, being registering the textures. Now, unlike the vanilla furnace, which has 2 separate blocks for on/off state, I am using metadata to do this. Now my problem is that the front texture doesn't update when the machine is on, everything else except this works. And I have a theory as to why; The registerBlockIcons method is only called when the block is created, now this isn't a problem for the vanilla furnace, as it replaces the off block with the on block, and when it does this, it is technically creating a new block, and so is re registering the textures. With my block, in my updateMachineState method (my equivalent to updateFurnaceBlockState) I am adding 1 to the metadata to set the machines state to on, and this is working fine, even with the rotations, I made it print out the metadata, and it does what I need it to. Now I have also made it print out the resource location (in the updateMachineState method) and it does update the texture name properly. Now all I need to do and cant figure out is how to re call the registerBlockIcons method, if I can do that, then it should work.

 

Any ideas on how to recall this method?

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Your best bet is to register all the textures at once, and then just switch between those. That way, you don't need to re-run the registerBlockIcons method.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Well, you can just do something like this:

public void registerBlockIcons(IIconRegister reg)
{
    this.icon0=reg.registerIcon("modid:icon0");
    this.icon1=reg.registerIcon("modid:icon1");
    this.icon2=reg.registerIcon("modid:icon2");
    //etc...
}

And then, where you return the icons, you need to return diffferent icons based on the metadata.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Okay, so I have updated my getIcon method to this:

 

        public IIcon getIcon(int side, int meta) {

	if (side == 0 || side == 1) {
		if (side == 0) return this.sideBottom;
		if (side == 1) return this.sideTop;
	} else {
		if (meta == 0 || meta == 1) {
			if (this.isActive) return side == 2 ? this.sideFrontOn : this.blockIcon;
			else return side == 2 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 2 || meta == 3) {
			if (this.isActive) return side == 5 ? this.sideFrontOn : this.blockIcon;
			else return side == 5 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 4 || meta == 5) {
			if (this.isActive) return side == 3 ? this.sideFrontOn : this.blockIcon;
			else return side == 3 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 6 || meta == 7) {
			if (this.isActive) return side == 4 ? this.sideFrontOn : this.blockIcon;
			else return side == 4 ? this.sideFrontOff : this.blockIcon;
		}
	}
	return blockIcon;
}

 

just a note; I have 8 metadata values, 0, 2, 4, and 6 being the rotational values while off, and 1, 3, 5, and 7 being the rotational values while on. So to turn the machine on, one is added to the metadata.

 

Should this work? I am loading my game now to find out, but it takes a while to load as I have several other mods installed.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Okay, so the texture does now update, but with weird consequences... And this is weird because I have no static fields or methods anywhere in my tile or block. So what is happening is well, when one machine in the world is off, and another is placed, it is fine, but if a second machine is placed with the first one on, it rotates to face the direction of the first block, and both of them update to the off texture. also when I mouse over the block in the world, the texture on the block in my hand changes to the one I am looking at. Now the way I am rotating my block is just reordering the textures on the faces depending on what angle the player is at relative to the block when placed. This is actually the only way (I know of) to do this, because I dont think that the block can actually physically rotate.

 

Any help on this?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

The thing is though, I really dont know where the problem is at all, so I will post my whole class (bare in mind, this class is designed to support all of my machines, it isnt just for this machine, but atm I only have this machine, I have no others)

 

Also, I have alot of custom methods. and it is a long class (about 300 lined)

 

 

Warning; Vary disorganized code... I will work on organizing this code once it is all working, until then, my priority is getting it working.

package generator.net.theepictekkit.generator.common.blocks.advanced.machines;

import generator.net.theepictekkit.generator.Generator;
import generator.net.theepictekkit.generator.Reference;
import generator.net.theepictekkit.generator.common.blocks.BlockHandler;
import generator.net.theepictekkit.generator.common.blocks.MachineType;
import generator.net.theepictekkit.generator.common.blocks.MachineType.Type;
import generator.net.theepictekkit.generator.common.tileentity.TileEntityFurnaceBasic;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockMachine extends BlockContainer {

//Note: Metadata values: 0, 2, 4, 6 = orientation off; 1, 3, 5, 7 = orientation on

public MachineType type = new MachineType();
public Block block = null;
public boolean keepInv;
public boolean isActive;
public boolean spawnParticle;
public String state; // Texture Name End
private String modid = Reference.MODID;
private float machineLightValue = 0.0F;
private Random rand = new Random();

//Side id		- Relative		-ForgeDirection
public IIcon sideBottom; 	//Side 0 		- Bottom		-DOWN
public IIcon sideTop;		//Side 1 		- Top			-UP
public IIcon sideFrontOn;	//Side 2 		- Front			-NORTH
public IIcon sideFrontOff;
//Side 3 		- Back			-SOUTH
public IIcon sideLeft;	 	//Side 4 		- Left			-WEST
public IIcon sideRight;	 	//Side 5		- Right			-EAST

public BlockMachine(Material mat, Type type) {
	super(mat);

	this.type.setMachineType(type);
	this.setHardness(3.0F);
	this.setLightLevel(machineLightValue);
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {

	if (side == 0 || side == 1) {
		if (side == 0) return this.sideBottom;
		if (side == 1) return this.sideTop;
	} else {
		if (meta == 0 || meta == 1) {
			if (this.isActive) return side == 2 ? this.sideFrontOn : this.blockIcon;
			else return side == 2 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 2 || meta == 3) {
			if (this.isActive) return side == 5 ? this.sideFrontOn : this.blockIcon;
			else return side == 5 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 4 || meta == 5) {
			if (this.isActive) return side == 3 ? this.sideFrontOn : this.blockIcon;
			else return side == 3 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 6 || meta == 7) {
			if (this.isActive) return side == 4 ? this.sideFrontOn : this.blockIcon;
			else return side == 4 ? this.sideFrontOff : this.blockIcon;
		}
	}
	return blockIcon;
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister icon) {
	this.sideBottom = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Bottom");
	this.sideTop = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Top");
	this.sideFrontOn = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Front_on");
	this.sideFrontOff = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Front_off");
	this.sideLeft = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) +  "_Left");
	this.sideRight = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Right");
	this.blockIcon = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Back");
}


public void setState(int meta) {

	this.block = getBlock();
	/*if ((meta == 1) || (meta == 3) || (meta == 5) || meta == 7) {
		this.state = "on";
		this.isActive = true;
	} else {
		this.state = "off";
		this.isActive = false;
	}*/
}

public void updateBlockState(boolean isActive, World world, int x, int y, int z) {
	System.out.println("Updating Block");
	int meta = world.getBlockMetadata(x, y, z);
	TileEntity tile = world.getTileEntity(x, y, z);
	keepInv = true;

	if (block != null) {
		if ((isActive)) {
			this.isActive = true;
			System.out.println(isActive);
			this.randomDisplayTick(world, x, y, z, rand);
			if (meta == 0) world.setBlock(x, y, z, block, 1, 2);
			if (meta == 2) world.setBlock(x, y, z, block, 3, 2);
			if (meta == 4) world.setBlock(x, y, z, block, 5, 2);
			if (meta == 6) world.setBlock(x, y, z, block, 7, 2);

		} else {
			this.isActive = false;
			if (meta == 1) world.setBlock(x, y, z, block, 0, 2);
			if (meta == 3) world.setBlock(x, y, z, block, 2, 2);
			if (meta == 5) world.setBlock(x, y, z, block, 4, 2);
			if (meta == 7) world.setBlock(x, y, z, block, 6, 2);
		}
	}

	keepInv = false;
	if (tile != null) {
		tile.validate();
		world.setTileEntity(x, y, z, tile);
	}
}

public void onBlockAdded(World world, int x, int y, int z) {
	super.onBlockAdded(world, x, y, z);
	this.setDefaultDirection(world, x, y, z);
}

private void setDefaultDirection(World world, int x, int y, int z) {

	if (!world.isRemote) {

		Block block = world.getBlock(x, y, z - 1);
		Block block1 = world.getBlock(x, y, z + 1);
		Block block2 = world.getBlock(x - 1, y, z);
		Block block3 = world.getBlock(x + 1, y, z);
		byte b0 = 3;

		if (block.func_149730_j() && !block1.func_149730_j()) {
			b0 = 4;
		} if (block1.func_149730_j() && !block.func_149730_j()) {
			b0 = 0;
		} if (block2.func_149730_j() && !block3.func_149730_j()) {
			b0 = 2;
		} if (block3.func_149730_j() && !block2.func_149730_j()) {
			b0 = 6;
		}
		world.setBlockMetadataWithNotify(x, y, z, b0, 2);
	}
}

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
	int l = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	if (l == 0) {
		world.setBlockMetadataWithNotify(x, y, z, 0, 2);
	} if (l == 1) {
		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
	} if (l == 2) {
		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
	} if (l == 3) {
		world.setBlockMetadataWithNotify(x, y, z, 6, 2);
	}
}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {

	if (!world.isRemote) {
		if (world.getTileEntity(x, y, z) != null) {
			FMLNetworkHandler.openGui(player, Generator.INSTANCE, Generator.guiIdBasicFurnace, world, x, y, z);
			return true;
		}
	}
	return true;
}

/*public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
	if (!this.keepInv) {

		TileEntity tile = getTile(world, x, y, z);

		if (tile != null) {
			for (int i1 = 0; i1 < tile.getSizeInventory(); ++i1) {
				ItemStack itemstack = tile.getStackInSlot(i1);

				if (itemstack != null)
				{
					float f = this.rand.nextFloat() * 0.8F + 0.1F;
					float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
					float f2 = this.rand.nextFloat() * 0.8F + 0.1F;

					while (itemstack.stackSize > 0)
					{
						int j1 = this.rand.nextInt(21) + 10;

						if (j1 > itemstack.stackSize)
						{
							j1 = itemstack.stackSize;
						}

						itemstack.stackSize -= j1;
						EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));

						if (itemstack.hasTagCompound())
						{
							entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
						}

						float f3 = 0.05F;
						entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3);
						entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F);
						entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3);
						world.spawnEntityInWorld(entityitem);
					}
				}
			}

			world.func_147453_f(x, y, z, block);
		}
	}

	super.breakBlock(world, x, y, z, block, meta);
}
 */
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
	if (this.spawnParticle) {

		int meta = world.getBlockMetadata(x, y, z);
		float f = (float)x + 0.5F;
		float f1 = (float)y + 0.0F + rand.nextFloat() * 6.0F / 16.0F;
		float f2 = (float)z + 0.5F;
		float f3 = 0.52F;
		float f4 = rand.nextFloat() * 0.6F - 0.3F;

		if (meta == 4) {
			world.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
		} else if (meta == 5) {
			world.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
		} else if (meta == 2) {
			world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
		} else if (meta == 3) {
			world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
			world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
		}
	}
}

public float setBrightness(boolean active, float value) {

	float level = 0.0F;

	if (active) {
		level = value;
	}
	return level;
}

public TileEntity getTile(World world, int x, int y, int z) {

	TileEntity tile = world.getTileEntity(x, y, z);

	if (tile != null) {
		switch (getMachine()) {

		case FURNACEBASIC : if (tile instanceof TileEntityFurnaceBasic) return (TileEntityFurnaceBasic)tile;
		default : break;
		}
	}
	return null;
}

public Block getBlock() {

	Block block = null;
	switch (getMachine()) {

	case FURNACEBASIC : return BlockHandler.machineBasicFurnace; 
	default : break;
	}
	return block;
}

public Type getMachine() {
	return type.getMachineType();
}

public ForgeDirection getOrientationFD(int meta) {

	ForgeDirection dir = null;

	if (meta == 0 || meta == 1) {
		dir = ForgeDirection.NORTH;
	} if (meta == 2 || meta == 3) {
		dir = ForgeDirection.EAST;
	} if (meta == 4 || meta == 5) {
		dir = ForgeDirection.SOUTH;
	} if (meta == 6 || meta == 7) {
		dir = ForgeDirection.WEST;
	}
	return dir;
}

@Override
public TileEntity createNewTileEntity(World world, int meta) {

	switch (getMachine()) {

	case FURNACEBASIC : return new TileEntityFurnaceBasic(3, "Basic Furnace", false, 64);
	default : return null;
	}
}
}

 

 

 

UPDATE: Sorry, but I forgot to include the tileentity(s). Warning; Also messy.

 

 

 

ThieEntityFurnaceBasic

package generator.net.theepictekkit.generator.common.tileentity;

import generator.net.theepictekkit.generator.common.blocks.advanced.machines.BlockMachine;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.BlockWoodSlab;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;

public class TileEntityFurnaceBasic extends TileEntityMachine {

public final int[] slotTop = new int[] {0};
public final int[] slotBottom = new int[] {2, 1};
public final int[] slotsSides = new int[] {1};

public int machineRunTime;
public int currentBurnTime;
public int machineProcessTime;
public int processTimeRequired = 100;

public TileEntityFurnaceBasic(int slots, String name, boolean dropSlot, int stackLimit) {
	this.slots = new ItemStack[slots];
	this.invName = name;
}

public void updateEntity() {
	System.out.println("Metadata at: x: " + xCoord + ", y: " + yCoord + ", z: " + zCoord + ": " + worldObj.getBlockMetadata(xCoord, yCoord, zCoord));

	Block block = worldObj.getBlock(xCoord, yCoord, zCoord);
	if (block instanceof BlockMachine) {
		System.out.println("Block instance of Machine");
		machine = (BlockMachine)block;
	}

	updateFurnace();
}

public void updateFurnace() {
	boolean isBurning = this.machineRunTime > 0;
	boolean bool = false;

	if (this.machineRunTime > 0) {
		isActive = true;
		worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
	} else {
		this.isActive = false;
	}

	machine.isActive = isActive;

	if (worldObj.getBlock(xCoord, yCoord, zCoord) != null) {
		if (machine != null && isActive) {
			machine.setState(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
			machine.updateBlockState(isActive, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
	}
	if (this.machineRunTime > 0) {
		--this.machineRunTime;
	}

	if (!this.worldObj.isRemote) {
		if (this.slots != null && slots.length > 0) {
			if (this.machineRunTime != 0 || this.slots[1] != null && this.slots[0] != null) {
				if (this.machineRunTime == 0 && this.canSmelt()) {
					this.currentBurnTime = this.machineRunTime = getBurnTime(this.slots[1]);

					if (this.machineRunTime > 0) {
						bool = true;

						if (this.slots[1] != null) {
							--this.slots[1].stackSize;

							if (this.slots[1].stackSize == 0) {
								this.slots[1] = slots[1].getItem().getContainerItem(slots[1]);
							}
						}
					}
				} if (this.isRunning() && this.canSmelt()) {
					++this.machineProcessTime;

					if (this.machineProcessTime == processTimeRequired) {
						this.machineProcessTime = 0;
						this.smeltItem();
						bool = true;
					}
				} else {
					this.machineProcessTime = 0;
				}
			}
		}

		if (isBurning != this.machineRunTime > 0) {
			bool = true;
		} else {
			bool = false;
		}
	}

	if (bool) {
		this.markDirty();
	}
}

public boolean isRunning() {
	return this.machineRunTime > 0;
}

@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
	return slot == 2 ? false : (slot == 1 ? isItemFuel(stack) : true);
}

public boolean isItemFuel(ItemStack stack) {
	return getBurnTime(stack) > 0;
}

public void smeltItem() {
	if (this.canSmelt()) {
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if (this.slots[2] == null) {
			this.slots[2] = itemstack.copy();
		} else if (this.slots[2].getItem() == itemstack.getItem()) {
			this.slots[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
		}
		--this.slots[0].stackSize;

		if (this.slots[0].stackSize <= 0) {
			this.slots[0] = null;
		}
	}
}

public boolean canSmelt() {
	if (this.slots[0] == null) {
		return false;
	} else {
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);
		if (itemstack == null) return false;
		if (this.slots[2] == null) return true;
		if (!this.slots[2].isItemEqual(itemstack)) return false;
		int result = slots[2].stackSize + itemstack.stackSize;
		return result <= getInventoryStackLimit() && result <= this.slots[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
	}
}

public int getBurnTime(ItemStack stack) {
	if (stack != null) {
		Item item = stack.getItem();

		if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
			Block block = Block.getBlockFromItem(item);

			if (block.getMaterial() == Material.wood) {

				if (block instanceof BlockWoodSlab) return 300;
				else return 600;

			}
			if (block == Blocks.coal_block) return 32000;
			if ((item instanceof ItemTool) || (item instanceof ItemSword) || (item instanceof ItemHoe)) {
				if ((((ItemTool)item).getToolMaterialName().equals("WOOD")) || (((ItemSword)item).getToolMaterialName().equals("WOOD")) || (((ItemHoe)item).getToolMaterialName().equals("WOOD"))) return 400;
			}
			if (item == Items.stick) return 200;
			if (item == Items.coal) return 1600;
			if (item == Items.lava_bucket) return 60000;
			if (item == Item.getItemFromBlock(Blocks.sapling)) return 200;
			if (item == Items.blaze_rod) return 6200;
			if (item == Items.blaze_powder) return 3100;
			if (item == Items.nether_star) return 640000;
			return GameRegistry.getFuelValue(stack);
		}
	}

	return 0;
}

public int getProcessTimeScaled(int scale) {
	return this.machineProcessTime * scale / processTimeRequired;
}

public int getRunTimeRemainingScaled(int scale) {
	if (this.machineRunTime == 0) this.machineRunTime = this.processTimeRequired;

	return this.machineRunTime * scale / this.currentBurnTime;
}

@Override
public int[] getAccessibleSlotsFromSide(int side) {
	return side == 0 ? this.slotBottom : (side == 1 ? this.slotTop : this.slotsSides);
}

@Override
public boolean canInsertItem(int slot, ItemStack stack, int side) {
	return this.isItemValidForSlot(slot, stack);
}

@Override
public boolean canExtractItem(int slot, ItemStack item, int side) {
	return side != 0 || slot != 1 || item.getItem() == Items.bucket;
}

}

 

TileEntityMachine

package generator.net.theepictekkit.generator.common.tileentity;

import generator.api.energy.IEnergyConsumer;
import generator.net.theepictekkit.generator.common.blocks.advanced.machines.BlockMachine;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

public abstract class TileEntityMachine extends TileEntity implements ISidedInventory, IEnergyConsumer {

public int invSize;
String invName;
public boolean dropContentsOnClose;
public int stackLimit = 64;
public BlockMachine machine;

public boolean isActive;

public ItemStack[] slots = new ItemStack[0];

public TileEntityMachine(int slots, String name, boolean dropSlot, int stackLimit) {
	this.invSize = slots;
	this.invName = name;
	this.dropContentsOnClose = dropSlot;
	this.stackLimit = stackLimit;
}

public TileEntityMachine() {

}

public void updateEntity() {

}

@Override
public int getSizeInventory() {
	return slots.length;
}

@Override
public ItemStack getStackInSlot(int slot) {

	return slots[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amount) {
	if (this.slots[slot] != null) {
		ItemStack itemstack;

		if (this.slots[slot].stackSize <= amount) {
			itemstack = this.slots[slot];
			this.slots[slot] = null;
			return itemstack;
		} else {
			itemstack = this.slots[slot].splitStack(amount);

			if (this.slots[slot].stackSize == 0) {
				this.slots[slot] = null;
			}

			return itemstack;
		}
	} else {
		return null;
	}
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	if (this.dropContentsOnClose) {
		if (this.slots[slot] != null) {
			ItemStack itemstack = this.slots[slot];
			this.slots[slot] = null;
			return itemstack;
		}
	} else {
		return null;
	}
	return null;
}

@Override
public void setInventorySlotContents(int slot, ItemStack item) {
	this.slots[slot] = item;

	if (item != null && item.stackSize > this.getInventoryStackLimit()) {
		item.stackSize = this.getInventoryStackLimit();
	}
}

@Override
public String getInventoryName() {
	return this.hasCustomInventoryName() ? this.invName : "container.null";
}

@Override
public boolean hasCustomInventoryName() {
	return this.invName != null && this.invName.length() > 0;
}

public void setInvName(String name) {
	this.invName = name;
}

@Override
public int getInventoryStackLimit() {
	return this.stackLimit;
}

@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
	return true;
}

@Override
public void openInventory() {

}

@Override
public void closeInventory() {

}

@Override
public abstract boolean isItemValidForSlot(int slot, ItemStack stack);



@Override
public abstract int[] getAccessibleSlotsFromSide(int side);

@Override
public abstract boolean canInsertItem(int slot, ItemStack stack, int side);

@Override
public abstract boolean canExtractItem(int slot, ItemStack item, int side);

@Override
public void setEnergyHandlerVariables() {

}

@Override
public float receiveEnergy(ForgeDirection dir, float maxReceive, boolean simulate) {
	return 0;
}

@Override
public float extractEnergy(ForgeDirection dir, float maxExtract,
		boolean simulate) {
	return 0;
}

@Override
public float getEnergyStored(ForgeDirection dir) {
	return 0;
}

@Override
public float getMaxEnergyStored(ForgeDirection dir) {
	return 0;
}

@Override
public boolean canConnect(ForgeDirection dir) {
	return false;
}

@Override
public int energyUsedToExist() {
	return 0;
}

@Override
public int energyUsedToRun() {
	return 0;
}

@Override
public void energyToExist(int energyNeeded, boolean doSomething) {

}

@Override
public void exceedMaxInput(int maxInput, boolean canRun) {

}
}
//Ignore all my energy methods, they are unused at the moment (also unfinished)

 

 

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

At the beginning of your class, all of these declarations are shared between all blocks in the world. That means that all blocks of that type in the world, will emit the same light, are all active at the same time and they will all spawn particles in the world at the same time. You probably need to store those in the TileEntity.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Okay then... what about the vanilla furnace though? variables like these were stored in the block, not the tile... im confused now

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

So out of the variables I have in the block, which ones should I store in the tile? I know things like the modid I wouldn't, but what about things like the MachineType type variable? MachineType is an enum to store what machine this class belongs to (not needed yet, but will be useful when I have multiple machines sharing this class).

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Also, aren't things only shared between all instances of a class if the variable has a static modifier?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Ohh, ok, now I understand, I was thinking that because when you register the block you register it as a new block, it creates a new instance for each... ok, i get it now.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Also, unrelated, but I have a question that I have been curious about for a while, what is the "private static final String __OBFID = "CL_000SomeNumberHere";" that I see in many vanilla classes?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Okay.

 

Update on my block; I Have moved the methods in the block class to the tileentity, as this class supports all my machines, I also have a tileentity that all my machines tileentitys extend, so I have moved them all to there, I have also moved the updateBlockState method to the tileentity too.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

I would also like to know how to make the ItemBlock in the players inventory render the front icon, at the moment, it just renders the blockIcon icon on all sides, and in the players hand, it renders whatever face the player is mousing over.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

<associatedBlock>getBlockTextureFromSide(1) {{ which calls getIcon(1, 0) }} returns that ItemBlock's texture; that is, unless you override the Icon or the getIconFromDamage(int dmg) method.

So, your block getIcon(side,meta) method should return the front icon when it sees side 1 and meta 0.

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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