Home » Language IDEs » Java Development Tools (JDT) » Custom Furnace not changing texture 1.7.10(Minecraft Mod Development)
Custom Furnace not changing texture 1.7.10 [message #1801532] |
Tue, 22 January 2019 01:28 |
Marco Barros Messages: 3 Registered: January 2019 |
Junior Member |
|
|
Hello guys,
I was working on my custom furnace and what happened is that when I put the fuel and an item to process, the minecraft in the eclipse crashes and when I open it again, the furnace is processing the item but the texture of the furnace block keeps the same, it doesn't change to the active one. The Minecraft version is 1.7.10.
Here is my TileEntity Class:
package lassisolet.grandchase.tileentity;
import cpw.mods.fml.common.registry.GameRegistry;
import lassisolet.grandchase.blocks.FornalhaDoAcoNegroIDLE;
import lassisolet.grandchasemod.main.Grand_Chase_Mod_MainClass;
import lassisolet.grandchasemod.tabs.Grand_Chase_Mod_Blocks;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.RecipeBookCloning;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import lassisolet.grandchasemod.recipes.FornalhaDoAcoNegroReceitas;
public class TileEntityFornalhaDoAcoNegro_ extends TileEntity implements ISidedInventory {
private String localizedName;
private static final int[] slots_top = new int[]{0};
private static final int[] slots_bottom = new int[]{2, 1};
private static final int[] slots_side = new int[]{1};
private ItemStack[] slots = new ItemStack [3];
public int furnaceSpeed = 150;
/**
* The number of ticks that the furnace will keep burning
*/
public int burnTime;
/**
* The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for
*/
public int currentItemBurnTime;
/**
* The number of ticks that the current item has been cooking for
*/
public int cookTime;
public void setGuiDisplayName(String displayName) {
this.localizedName = displayName;
}
public String getInventoryName() {
return this.hasCustomInventoryName() ? this.localizedName : "container.fornalhadoaconegroidle";
}
public boolean hasCustomInventoryName() {
return this.localizedName != null && this.localizedName.length() > 0;
}
public int getSizeInventory() {
return this.slots.length;
}
@Override
public ItemStack getStackInSlot(int var1) {
return this.slots[var1];
}
@Override
public ItemStack decrStackSize(int var1, int var2) {
if(this.slots[var1] != null){
ItemStack itemstack;
if(this.slots[var1].stackSize <= var2 ){
itemstack = this.slots[var1];
this.slots[var1] = null;
return itemstack;
}else{
itemstack = this.slots[var1].splitStack(var2);
if(this.slots[var1].stackSize == 0) {
this.slots[var1] = null;
}
return itemstack;
}
}else{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
if(this.slots[i]!= null) {
ItemStack itemstack = this.slots[i];
this.slots[i] = null;
return itemstack;
}
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
this.slots[i] = itemstack;
if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {
itemstack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
}
public void openInventory() {}
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return i == 2 ? false : (i == 1 ? isItemFuel(itemstack) : true);
}
public static boolean isItemFuel (ItemStack itemstack) {
return getItemBurnTime(itemstack) > 0;
}
private static int getItemBurnTime(ItemStack itemstack) {
if(itemstack == null){
return 0;
}else{
Item item = itemstack.getItem();
if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
Block block = Block.getBlockFromItem(item);
}
if(item == Items.blaze_rod) return 18000;
if(item == Items.blaze_powder) return 10000;
if(item == Items.lava_bucket) return 20000;
if(item == Items.blaze_rod) return 2400;
}
return GameRegistry.getFuelValue(itemstack);
}
public boolean isBurning() {
return this.burnTime > 0;
}
public void updateEntity() {
boolean flag = this.burnTime > 0;
boolean flag1 = false;
if(this.isBurning()) {
this.burnTime--;
}
if(!this.worldObj.isRemote) {
if(this.burnTime == 0 && this.canSmelt()) {
this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[1]);
if(this.isBurning()) {
flag1 = true;
if(this.slots[1] != null) {
this.slots[1].stackSize--;
if(this.slots[1].stackSize == 0) {
this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
}
}
}
}
if(this.isBurning() && this.canSmelt()) {
this.cookTime++;
if(this.cookTime == this.furnaceSpeed) {
this.cookTime = 0;
this.smeltItem();
flag1 = true;
}
}else{
this.cookTime = 0;
}
if(flag != this.isBurning()) {
flag1 = true;
FornalhaDoAcoNegroIDLE.updateFornalhaDoAcoNegroIDLEBlockState(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
if(flag1) {
this.markDirty();
}
}
public boolean canSmelt() {
if (this.slots[0] == null) {
return false;
}else{
ItemStack itemstack = lassisolet.grandchasemod.recipes.FornalhaDoAcoNegroReceitas.smelting().getSmeltingResult(this.slots[0]);
//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 = this.slots[2].stackSize + itemstack.stackSize;
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
}
}
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].isItemEqual(itemstack)) {
this.slots[2].stackSize += itemstack.stackSize;
}
this.slots[0].stackSize--;
if(this.slots[0].stackSize <= 0) {
this.slots[0] = null;
}
}
}
@Override
public int[] getAccessibleSlotsFromSide(int var1) {
return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_side);
}
@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
return this.isItemValidForSlot(i, itemstack);
}
@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
return j != 0 || i != 1 || itemstack.getItem() == Items.bucket;
}
public int getBurnTimeRemainingScaled(int i) {
if(this.currentItemBurnTime ==0) {
this.currentItemBurnTime = this.furnaceSpeed;
}
return this.burnTime * i / this.currentItemBurnTime;
}
public int getCookProgressScaled(int i) {
return this.cookTime * i / this.furnaceSpeed;
}
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("Items", 10);
this.slots = new ItemStack[this.getSizeInventory()];
for(int i = 0; i < list.tagCount(); i++) {
NBTTagCompound compound = (NBTTagCompound) list.getCompoundTagAt(i);
byte b = compound.getByte("Slot");
if(b >= 0 && b < this.slots.length) {
this.slots[b] = ItemStack.loadItemStackFromNBT(compound);
}
}
this.burnTime = (int)nbt.getShort("BurnTime");
this.cookTime = (int)nbt.getShort("CookTime");
this.currentItemBurnTime = (int)nbt.getShort("CurrentBurnTime");
if(nbt.hasKey("CustomName")) {
this.localizedName = nbt.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setShort("BurnTime", (short)this.burnTime);
nbt.setShort("CookTime", (short)this.cookTime);
nbt.setShort("CurrentBurnTime", (short)this.currentItemBurnTime);
NBTTagList list = new NBTTagList();
for (int i = 0; i < this.slots.length; i++) {
if(this.slots[i] != null) {
NBTTagCompound compound = new NBTTagCompound();
compound.setByte("Slot", (byte)i);
this.slots[i].writeToNBT(compound);
list.appendTag(compound);
}
}
nbt.setTag("Items", list);
if (this.hasCustomInventoryName()) {
nbt.setString("CustomName", this.localizedName);
}
}
}
FurnaceIDLE class:
package lassisolet.grandchase.blocks;
import java.util.Random;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import lassisolet.grandchase.tileentity.TileEntityFornalhaDoAcoNegro_;
import lassisolet.grandchasemod.lib.Strings;
import lassisolet.grandchasemod.main.Grand_Chase_Mod_MainClass;
import lassisolet.grandchasemod.tabs.Grand_Chase_Mod_Blocks;
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.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import lassisolet.grandchasemod.gui.FornalhaDoAcoNegro;
public class FornalhaDoAcoNegroIDLE extends BlockContainer {
private final boolean isActive;
@SideOnly(Side.CLIENT)
private IIcon iconFront;
@SideOnly(Side.CLIENT)
private IIcon iconTop;
private static boolean keepInventory;
private Random rand = new Random();
public FornalhaDoAcoNegroIDLE(boolean isActive) {
super(Material.iron);
this.isActive = isActive;
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon(Strings.MODID + ":" + "BlackSteelFurnaceSideOff");
this.iconFront = iconRegister.registerIcon(Strings.MODID + ":" + (this.isActive ? "BlackSteelFurnaceFrontOn" : "BlackSteelFurnaceFrontOff"));
this.iconTop = iconRegister.registerIcon(Strings.MODID + ":" + "BlackSteelFurnaceTopOff");
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
return metadata == 0 && side == 3 ? this.iconFront : side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side == metadata ? this.iconFront : this.blockIcon));
//return side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side != metadata ? this.blockIcon : this.iconFront));
}
public Item getItemDropped(int i, Random random, int j) {
return Item.getItemFromBlock(GerenciadorDeBlocos.fornalhadoaconegroidle);
}
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 b1 = world.getBlock(x, y, z - 1);
Block b2 = world.getBlock(x, y, z + 1);
Block b3 = world.getBlock(x - 1, y, z);
Block b4 = world.getBlock(x + 1, y, z);
byte b0 = 3;
if(b1.func_149730_j() && !b2.func_149730_j()) {
b0 = 3;
}
if(b2.func_149730_j() && !b1.func_149730_j()) {
b0 = 2;
}
if(b3.func_149730_j() && !b4.func_149730_j()) {
b0 = 5;
}
if(b4.func_149730_j() && !b3.func_149730_j()) {
b0 = 4;
}
world.setBlockMetadataWithNotify(x, y, x, b0, 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) {
FMLNetworkHandler.openGui(player, Grand_Chase_Mod_MainClass.instance, GerenciadorDeBlocos.guiIDFornalhaDoAcoNegro, world, x, y, z);
}
return true;
}
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileEntityFornalhaDoAcoNegro_();
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random random) {
if(this.isActive) {
int direction = world.getBlockMetadata(x, y, z);
float x1 = (float)x + 0.5F;
float y1 = (float)y + random.nextFloat();
float z1 = (float)z + 0.5F;
float f = 0.52F;
float f1 = random.nextFloat() * 0.6F - 0.3F;
if(direction == 4){
world.spawnParticle("smoke", (double)(x1 - f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
world.spawnParticle("flame", (double)(x1 - f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
}
if(direction == 5){
world.spawnParticle("smoke", (double)(x1 + f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
world.spawnParticle("flame", (double)(x1 + f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
}
if(direction == 2){
world.spawnParticle("smoke", (double)(x1 + f1), (double)(y1), (double)(z1 - f), 0D, 0D, 0D);
world.spawnParticle("flame", (double)(x1 + f1), (double)(y1), (double)(z1 - f), 0D, 0D, 0D);
}
if(direction == 3){
world.spawnParticle("smoke", (double)(x1 + f1), (double)(y1), (double)(z1 + f), 0D, 0D, 0D);
world.spawnParticle("flame", (double)(x1 + f1), (double)(y1), (double)(z1 + f), 0D, 0D, 0D);
}
}
}
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) {
int l = MathHelper.floor_double((double)(entityplayer.rotationYaw * 4.0F / 360.F) + 0.5D) & 3;
if(l == 0) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if(l == 1) {
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if(l == 2) {
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if(l == 3) {
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
if(itemstack.hasDisplayName()) {
((TileEntityFornalhaDoAcoNegro_)world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
}
}
public static void updateFornalhaDoAcoNegroIDLEBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) {
int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord);
keepInventory = true;
if(active) {
worldObj.setBlock(xCoord, yCoord, zCoord, GerenciadorDeBlocos.fornalhadoaconegroactive);
}else{
worldObj.setBlock(xCoord, yCoord, zCoord, GerenciadorDeBlocos.fornalhadoaconegroidle);
}
keepInventory = false;
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);
if(tileentity != null) {
tileentity.validate();
worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity);
}
}
public void breakBlock(World world, int x, int y, int z, Block oldblock, int oldMetadata) {
if(!keepInventory) {
TileEntityFornalhaDoAcoNegro_ tileentity = (TileEntityFornalhaDoAcoNegro_) world.getTileEntity(x, y, z);
if(tileentity != null) {
for(int i = 0; i < tileentity.getSizeInventory(); i++) {
ItemStack itemstack = tileentity.getStackInSlot(i);
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 j = this.rand.nextInt(21) + 10;
if(j > itemstack.stackSize) {
j = itemstack.stackSize;
}
itemstack.stackSize -= j;
EntityItem item = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
if(itemstack.hasTagCompound()) {
item.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
world.spawnEntityInWorld(item);
}
}
}
world.func_147453_f(x, y, z, oldblock);
}
}
super.breakBlock(world, x, y, z, oldblock, oldMetadata);
}
public Item getItem(World world, int x, int y, int z) {
return Item.getItemFromBlock(GerenciadorDeBlocos.fornalhadoaconegroidle);
}
}
Thanks for the help
|
|
| | |
Goto Forum:
Current Time: Thu Apr 25 23:06:12 GMT 2024
Powered by FUDForum. Page generated in 0.02567 seconds
|