• 0

    posted a message on Two Containers nearly identical.... One gets an error.

    In case it helps here are these:


    [07:50:26] [pool-2-thread-1/WARN] [mojang/YggdrasilMinecraftSessionService]: Couldn't look up profile properties for [email protected][id=9a0ac3e8-2a19-3175-bbea-119d15dbea78,name=Player94,properties={},legacy=false]
    com.mojang.authlib.exceptions.AuthenticationException: The client has sent too many requests within a certain amount of time
    at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:79) ~[YggdrasilAuthenticationService.class:?]
    at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillGameProfile(YggdrasilMinecraftSessionService.java:180) [YggdrasilMinecraftSessionService.class:?]
    at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:60) [YggdrasilMinecraftSessionService$1.class:?]
    at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:57) [YggdrasilMinecraftSessionService$1.class:?]
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3716) [guava-21.0.jar:?]
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2424) [guava-21.0.jar:?]
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2298) [guava-21.0.jar:?]
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2211) [guava-21.0.jar:?]
    at com.google.common.cache.LocalCache.get(LocalCache.java:4154) [guava-21.0.jar:?]
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158) [guava-21.0.jar:?]
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147) [guava-21.0.jar:?]
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153) [guava-21.0.jar:?]
    at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillProfileProperties(YggdrasilMinecraftSessionService.java:170) [YggdrasilMinecraftSessionService.class:?]
    at net.minecraft.client.Minecraft.getProfileProperties(Minecraft.java:3182) [Minecraft.class:?]
    at net.minecraft.client.resources.SkinManager$3.run(SkinManager.java:138) [SkinManager$3.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_191]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_191]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_191]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_191]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    [07:50:26] [Client thread/INFO] [minecraft/AdvancementList]: Loaded 3 advancements
    [07:50:27] [Server thread/FATAL] [minecraft/MinecraftServer]: Error executing task
    java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_191]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_191]
    at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    Caused by: java.lang.NullPointerException
    at kenneths_mods.kenneth_medieval_mod.init.machines.smithing_anvil.ContainerSmithingAnvil.<init>(ContainerSmithingAnvil.java:20) ~[ContainerSmithingAnvil.class:?]
    at kenneths_mods.kenneth_medieval_mod.util.ModGUIHandler.getServerGuiElement(ModGUIHandler.java:27) ~[ModGUIHandler.class:?]
    at net.minecraftforge.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:253) ~[NetworkRegistry.class:?]
    at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?]
    at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2809) ~[EntityPlayer.class:?]
    at kenneths_mods.kenneth_medieval_mod.init.machines.smithing_anvil.BlockSmithingAnvil.onBlockActivated(BlockSmithingAnvil.java:41) ~[BlockSmithingAnvil.class:?]
    at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:475) ~[PlayerInteractionManager.class:?]
    at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:769) ~[NetHandlerPlayServer.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_191]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_191]
    at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
    ... 5 more
    [07:50:28] [Server thread/INFO] [minecraft/IntegratedServer]: Saving and pausing game...
    [07:50:28] [Server thread/INFO] [minecraft/MinecraftServer]: Saving chunks for level 'Test16 7:46 AM 1/29/2019'/overworld
    [07:50:29] [Server thread/INFO] [minecraft/MinecraftServer]: Stopping server
    [07:50:29] [Server thread/INFO] [minecraft/MinecraftServer]: Saving players
    [07:50:29] [Server thread/INFO] [minecraft/NetHandlerPlayServer]: Player94 lost connection: Disconnected
    [07:50:29] [Server thread/INFO] [minecraft/MinecraftServer]: Player94 left the game
    [07:50:29] [Server thread/INFO] [minecraft/NetHandlerPlayServer]: Stopping singleplayer server as player logged out
    [07:50:29] [Server thread/INFO] [minecraft/MinecraftServer]: Saving worlds
    [07:50:29] [Server thread/INFO] [minecraft/MinecraftServer]: Saving chunks for level 'Test16 7:46 AM 1/29/2019'/overworld
    [07:50:29] [Server thread/INFO] [FML]: Unloading dimension 0
    [07:50:29] [Server thread/INFO] [FML]: Applying holder lookups
    [07:50:29] [Server thread/INFO] [FML]: Holder lookups applied
    [07:50:30] [Client thread/INFO] [minecraft/Minecraft]: Stopping!
    [07:50:30] [Client thread/INFO] [minecraft/SoundManager]: SoundSystem shutting down...
    [07:50:30] [Client thread/WARN] [minecraft/SoundManager]: Author: Paul Lamb, www.paulscode.com
    Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release




    Common Proxy Registering my Tile entities:


    package kenneths_mods.kenneth_medieval_mod.proxy;
    
    import kenneths_mods.kenneth_medieval_mod.init.blocks.BlockIronwoodLeaves;
    import kenneths_mods.kenneth_medieval_mod.init.blocks.BlockYewLeaves;
    import kenneths_mods.kenneth_medieval_mod.init.machines.advanced_campfire.TileEntityAdvancedCampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.bronze_furnace.TileEntityBronzeFurnace;
    import kenneths_mods.kenneth_medieval_mod.init.machines.campfire.TileEntityCampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.smithing_anvil.TileEntitySmithingAnvil;
    import kenneths_mods.kenneth_medieval_mod.init.machines.windmill.TESRWindmill;
    import kenneths_mods.kenneth_medieval_mod.init.machines.windmill.TileEntityWindmill;
    import kenneths_mods.kenneth_medieval_mod.util.Reference;
    import net.minecraftforge.fml.client.registry.ClientRegistry;
    import net.minecraftforge.fml.common.registry.GameRegistry;
    
    public class CommonProxy {
    	public void registerRenders () {}
    	
    	public void setGraphicsLevelIronwood (BlockIronwoodLeaves parBlock, boolean parFancyEnabled) {}
    	public void setGraphicsLevelYew (BlockYewLeaves parBlock, boolean parFancyEnabled) {}
    	
    	public void registerTileEntities () {
    		GameRegistry.registerTileEntity(TileEntityCampfire.class, Reference.MODID + ":campfire");
    		GameRegistry.registerTileEntity(TileEntityAdvancedCampfire.class, Reference.MODID + ":advanced_campfire");
    		GameRegistry.registerTileEntity(TileEntityBronzeFurnace.class, Reference.MODID + ":bronze_furnace");
    		GameRegistry.registerTileEntity(TileEntitySmithingAnvil.class, Reference.MODID + ":smithing_anvil");
    		
    		GameRegistry.registerTileEntity(TileEntityWindmill.class, Reference.MODID + ":windmill");
    		ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWindmill.class, new TESRWindmill());
    	}
    }



    And my reference class:


    package kenneths_mods.kenneth_medieval_mod.util;
    
    public class Reference {
    	public static final String MODID = "kenmod";
    	public static final String VERSION = "1.0";
    	public static final String NAME = "Kenneth's Medieval Mod";
    	
    	public static final String SERVER_PROXY_CLASS = "kenneths_mods.kenneth_medieval_mod.proxy.CommonProxy";
    	public static final String CLIENT_PROXY_CLASS = "kenneths_mods.kenneth_medieval_mod.proxy.ClientProxy";
    	
    	public static final int GUI_CAMPFIRE_ID = 0;
    	public static final int GUI_ADVANCED_CAMPFIRE_ID = 1;
    	public static final int GUI_BRONZE_FURNACE_ID = 2;
    	public static final int GUI_SMITHING_ANVIL_ID = 3;
    }
    Posted in: Modification Development
  • 0

    posted a message on Two Containers nearly identical.... One gets an error.

    I feel like my post are somehow not being registered anymore as I have not received a response to any of my posts for the past three weeks or so.... please respond if you can see my posts.

    Posted in: Modification Development
  • 0

    posted a message on Two Containers nearly identical.... One gets an error.

    There are two blocks, an advanced campfire, and a smithing anvil. The container of the advanced campfire works perfectly.... but the smithing anvil's container does not. I get a null pointer exception on line 20 of ContainerSmithingAnvil:


    package kenneths_mods.kenneth_medieval_mod.init.machines.smithing_anvil;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IContainerListener;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.IItemHandler;
    import net.minecraftforge.items.SlotItemHandler;
    
    public class ContainerSmithingAnvil extends Container {
    	
    	private final TileEntitySmithingAnvil tileentity;
    	private int smithTime;
    	
    	public ContainerSmithingAnvil (InventoryPlayer player, TileEntitySmithingAnvil tileentity) {
    		this.tileentity = tileentity;
    		IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    		this.addSlotToContainer(new SlotItemHandler(handler, 0, 39, 23));
    		this.addSlotToContainer(new SlotItemHandler(handler, 1, 39, 54));
    		this.addSlotToContainer(new SlotItemHandler(handler, 2, 79, 39) {
    			public boolean isItemValid(ItemStack stack) {
    				return false;
    			}
    		});
    		for(int y = 0; y < 3; y++) {
    			for(int x = 0; x < 9; x++) {
    				this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
    			}
    		}
    		for(int x = 0; x < 9; x++) {
    			this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    		}
    	}
    	@Override
    	public boolean canInteractWith(EntityPlayer playerIn) {
    		return true;
    	}
    	@Override
    	public void detectAndSendChanges() {
    		super.detectAndSendChanges();
    		for(int i = 0; i < this.listeners.size(); i++) {
    			IContainerListener listener = (IContainerListener)this.listeners.get(i);
    			if(this.smithTime != this.tileentity.getField(0)) {
    				listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
    			}
    		}
    		this.smithTime = this.tileentity.getField(0);
    	}
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
    		ItemStack itemstack = ItemStack.EMPTY;
            Slot slot = this.inventorySlots.get(index);
            if(slot != null && slot.getHasStack()) {
            	ItemStack itemstack1 = slot.getStack();
            	itemstack = itemstack1.copy();
            	int containerSlots = inventorySlots.size() - playerIn.inventory.mainInventory.size();
            	if (index < containerSlots) {
                	if(!this.mergeItemStack(itemstack1, containerSlots, inventorySlots.size(), true)) {
                		return ItemStack.EMPTY;
                	}
                } else if (!this.mergeItemStack(itemstack1, 0, containerSlots, false)) {
                	return ItemStack.EMPTY;
                }
                if (itemstack1.getCount() == 0) {
                	slot.putStack(ItemStack.EMPTY);
                } else {
                	slot.onSlotChanged();
                }
                if(itemstack1.getCount() == itemstack.getCount()) {
                	return ItemStack.EMPTY;
                }
                slot.onTake(playerIn, itemstack1);
            }
            return itemstack;
    	}
    	
    	public void onContainerClosed(EntityPlayer playerIn) {
    		super.onContainerClosed(playerIn);
    	}
    }
    



    The smithing anvil only differs from the advanced container by having an extra input slot.

    Here is the container for the advanced campfire:


    package kenneths_mods.kenneth_medieval_mod.init.machines.advanced_campfire;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IContainerListener;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.IItemHandler;
    import net.minecraftforge.items.SlotItemHandler;
    
    public class ContainerAdvancedCampfire extends Container {
    	
    	private final TileEntityAdvancedCampfire tileentity;
    	private int cookTime;
    	
    	public ContainerAdvancedCampfire (InventoryPlayer player, TileEntityAdvancedCampfire tileentity) {
    		this.tileentity = tileentity;
    		IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    		this.addSlotToContainer(new SlotItemHandler(handler, 0, 39, 34));
    		this.addSlotToContainer(new SlotItemHandler(handler, 1, 72, 34) {
    			public boolean isItemValid (ItemStack stack) {
    				return false;
    			}
    		});
    		for(int y = 0; y < 3; y++) {
    			for(int x = 0; x < 9; x++) {
    				this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
    			}
    		}
    		for(int x = 0; x < 9; x++) {
    			this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    		}
    	}
    	@Override
    	public boolean canInteractWith(EntityPlayer playerIn) {
    		return true;
    	}
    	@Override
    	public void detectAndSendChanges() {
    		super.detectAndSendChanges();
    		for(int i = 0; i < this.listeners.size(); i++) {
    			IContainerListener listener = (IContainerListener)this.listeners.get(i);
    			if(this.cookTime != this.tileentity.getField(0)) {
    				listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
    			}
    		}
    		this.cookTime = this.tileentity.getField(0);
    	}
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
    		ItemStack itemstack = ItemStack.EMPTY;
            Slot slot = this.inventorySlots.get(index);
            if(slot != null && slot.getHasStack()) {
            	ItemStack itemstack1 = slot.getStack();
            	itemstack = itemstack1.copy();
            	int containerSlots = inventorySlots.size() - playerIn.inventory.mainInventory.size();
            	if (index < containerSlots) {
                	if(!this.mergeItemStack(itemstack1, containerSlots, inventorySlots.size(), true)) {
                		return ItemStack.EMPTY;
                	}
                } else if (!this.mergeItemStack(itemstack1, 0, containerSlots, false)) {
                	return ItemStack.EMPTY;
                }
                if (itemstack1.getCount() == 0) {
                	slot.putStack(ItemStack.EMPTY);
                } else {
                	slot.onSlotChanged();
                }
                if(itemstack1.getCount() == itemstack.getCount()) {
                	return ItemStack.EMPTY;
                }
                slot.onTake(playerIn, itemstack1);
            }
            return itemstack;
    	}
    	
    	public void onContainerClosed(EntityPlayer playerIn) {
    		super.onContainerClosed(playerIn);
    	}
    }
    




    And here is the ModGUIHandler script:


    package kenneths_mods.kenneth_medieval_mod.util;
    
    import kenneths_mods.kenneth_medieval_mod.init.machines.advanced_campfire.ContainerAdvancedCampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.advanced_campfire.GUIAdvancedCampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.advanced_campfire.TileEntityAdvancedCampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.bronze_furnace.ContainerBronzeFurnace;
    import kenneths_mods.kenneth_medieval_mod.init.machines.bronze_furnace.GUIBronzeFurnace;
    import kenneths_mods.kenneth_medieval_mod.init.machines.bronze_furnace.TileEntityBronzeFurnace;
    import kenneths_mods.kenneth_medieval_mod.init.machines.campfire.ContainerCampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.campfire.GUICampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.campfire.TileEntityCampfire;
    import kenneths_mods.kenneth_medieval_mod.init.machines.smithing_anvil.ContainerSmithingAnvil;
    import kenneths_mods.kenneth_medieval_mod.init.machines.smithing_anvil.GUISmithingAnvil;
    import kenneths_mods.kenneth_medieval_mod.init.machines.smithing_anvil.TileEntitySmithingAnvil;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.common.network.IGuiHandler;
    
    public class ModGUIHandler implements IGuiHandler {
    
    	@Override
    	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		if(ID == Reference.GUI_CAMPFIRE_ID) return new ContainerCampfire(player.inventory, (TileEntityCampfire)world.getTileEntity(new BlockPos(x, y, z)));
    		if(ID == Reference.GUI_ADVANCED_CAMPFIRE_ID) return new ContainerAdvancedCampfire(player.inventory, (TileEntityAdvancedCampfire)world.getTileEntity(new BlockPos(x, y, z)));
    		if(ID == Reference.GUI_BRONZE_FURNACE_ID)return new ContainerBronzeFurnace(player.inventory, (TileEntityBronzeFurnace)world.getTileEntity(new BlockPos(x, y, z)));
    		if(ID == Reference.GUI_SMITHING_ANVIL_ID)return new ContainerSmithingAnvil(player.inventory, (TileEntitySmithingAnvil)world.getTileEntity(new BlockPos(x, y, z)));
    		return null;
    	}
    
    	@Override
    	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		if(ID == Reference.GUI_CAMPFIRE_ID) return new GUICampfire(player.inventory, (TileEntityCampfire)world.getTileEntity(new BlockPos(x, y, z)));
    		if(ID == Reference.GUI_ADVANCED_CAMPFIRE_ID) return new GUIAdvancedCampfire(player.inventory, (TileEntityAdvancedCampfire)world.getTileEntity(new BlockPos(x, y, z)));
    		if(ID == Reference.GUI_BRONZE_FURNACE_ID) return new GUIBronzeFurnace(player.inventory, (TileEntityBronzeFurnace)world.getTileEntity(new BlockPos(x, y, z)));
    		if(ID == Reference.GUI_SMITHING_ANVIL_ID) return new GUISmithingAnvil(player.inventory, (TileEntitySmithingAnvil)world.getTileEntity(new BlockPos(x, y, z)));
    		return null;
    	}
    
    }
    



    I don't know what is wrong.... both containers are the same except for the smithing anvil having an extra input slot. What is wrong?

    Line 20 of smithing anvil container:


    IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    Posted in: Modification Development
  • 0

    posted a message on Where can I find a armor template file for 32*32 texture?

    I am making a mod that adds blocks with 32*32 textures. Just wondering if there is a template out there for making modded armor textures. Thanks.

    Posted in: Modification Development
  • 0

    posted a message on Adding Timers to Items.

    Hi, I am making a mod that adds blacksmithing in a realistic manner. When someone wants to create a sword made out of steel (from the mod) they must first craft a sword blank, then heat treat it, then "quench and temper" it (a process that makes the sword strong and less likely to break in battle). The thing is items in real life stay hot for only a short amount of time. Is there a way to add a timer to my heated sword blank to where once it runs out of time it returns to a cooled sword blank?

    Posted in: Modification Development
  • 0

    posted a message on Make Custom Villager more Rare?

    Using jabelar's custom villager tutorials:

    http://jabelarminecraft.blogspot.com/p/minecraft-forge-modding-villagers.html

    I was able to create my own custom villager. The problem is last time I walked into a village on a superflat world, I noticed that there were a bunch of the villagers with the profession / careers I created. Is there any way to make villagers with a custom modded job to be more rare? Thanks.

    Posted in: Modification Development
  • 0

    posted a message on Strange inventory behaviour with my sawmill.

    Does anyone have a solution to this? I still can't find it.

    Posted in: Modification Development
  • 0

    posted a message on How to make an ore block that displays a second texture over the default stone texture?

    how would I make a block model with both layers?

    Posted in: Modification Development
  • 0

    posted a message on Tile entity changes block states of all similar blocks.

    I have been trying to get my campfire working for over a week now. Can someone please help?

    Posted in: Modification Development
  • 0

    posted a message on Tile entity changes block states of all similar blocks.

    I have created two blocks. A campfire, and a lit campfire. Both share the same tile entity script. both share the same GUI. both share the same container script. The problem is, when I click the button on the campfire GUI, the GUI affects all campfires in the world. By opening the GUI on one campfire and clicking on the "On/Off" button, instead of just the one campfire becoming a lit campfire, all campfires in the world turn into lit campfires. I can't seem to figure out how to fix this.


    Please help...



    The Campfire Block Script:



    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.KennethsMedievalModMain;
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockHorizontal;
    import net.minecraft.block.ITileEntityProvider;
    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.Minecraft;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.Mirror;
    import net.minecraft.util.Rotation;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    public class Campfire extends Block {
    	
    	public static final PropertyDirection FACING = BlockHorizontal.FACING;
    	protected String name;
    	
    	public Campfire(String name, boolean isOn) {
    		super(Material.WOOD);
    		setUnlocalizedName(name);
    		setRegistryName(name);
    		setHardness(1.5F);
    		setResistance(10);
    		setHarvestLevel("axe", 1);
    		setSoundType(SoundType.WOOD);
    		setCreativeTab(CreativeTabs.DECORATIONS);
    		this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
    	}
    	@Override
    	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    		if(worldIn.isRemote) {
    			return true;
    		} else {
    			TileEntity tileentity = worldIn.getTileEntity(pos);
    			if(tileentity instanceof CampfireTE) {
    				CampfireTE te = (CampfireTE)tileentity;
    				if(playerIn.getHeldItem(EnumHand.MAIN_HAND).getItem() == Item.getItemFromBlock(Blocks.LOG)) {
    					te.addFuel(playerIn);
    				} else {
    					playerIn.openGui(KennethsMedievalModMain.instance, Reference.CAMPFIRE_GUI_ID, worldIn, 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 (World worldIn, BlockPos pos, boolean active) {
    		IBlockState iblockstate = worldIn.getBlockState(pos);
    	    TileEntity tileentity = worldIn.getTileEntity(pos);
    	    if (active) {
    	        worldIn.setBlockState(pos, ModBlocks.lit_campfire.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    	    } else {
    	        worldIn.setBlockState(pos, ModBlocks.campfire.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    	    }
    	    if (tileentity != null) {
    	        tileentity.validate();
    	        worldIn.setTileEntity(pos, tileentity);
    	    }
    	}
    	@Override
    	public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
    		int x = pos.getX();
    		int y = pos.getY();
    		int z = pos.getZ();
    		Block block = this;
    		int i = x;
    		int j = y;
    		int k = z;
    		if (true) {
    			for (int l = 0; l < 5; ++l) {
    				double d0 = (double) ((float) i + 0.6F) + (double) (rand.nextFloat() - 0.5F) * 0.5D;
    				double d1 = ((double) ((float) j + 0.7F) + (double) (rand.nextFloat() - 0.5F) * 0.5D - 0.5F);
    				double d2 = (double) ((float) k + 0.6F) + (double) (rand.nextFloat() - 0.5F) * 0.5D;
    				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0, d1 + 0.2199999988079071D, d2, 0.0D, 0.0D, 0.0D);
    			}
    		}
    	}
    	@Override
    	public boolean hasTileEntity(IBlockState state) {
    		return true;
    	}
    	@Override
    	public TileEntity createTileEntity(World world, IBlockState state) {
    		return new CampfireTE();
    	}
    	@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, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    		if(stack.hasDisplayName()) {
    			TileEntity tileentity = worldIn.getTileEntity(pos);
    			if(tileentity instanceof CampfireTE) {
    				((CampfireTE)tileentity).setCustomName(stack.getDisplayName());
    			}
    		}
    	}
    	@Override
    	public IBlockState getStateFromMeta(int meta) {
    		EnumFacing enumfacing = EnumFacing.getFront(meta);
    		if(enumfacing.getAxis() == EnumFacing.Axis.Y) {
    			enumfacing = EnumFacing.NORTH;
    		}
    		return this.getDefaultState().withProperty(FACING, enumfacing);
    	}
    	@Override
    	public int getMetaFromState(IBlockState state) {
    		return ((EnumFacing)state.getValue(FACING)).getIndex();
    	}
    	@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[] {FACING});
    	}
    	@Override
    	public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
    		return true;
    	}
    	@Override
    	public boolean isOpaqueCube(IBlockState state) {
    		return false;
    	}
    	@Override
    	public boolean isFullBlock(IBlockState state) {
    		return false;
    	}
    }
    




    The Tile Entity:




    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.block.Block;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.ITickable;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.util.text.TextComponentTranslation;
    import net.minecraft.world.EnumSkyBlock;
    import net.minecraft.world.World;
    import net.minecraftforge.common.capabilities.Capability;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class CampfireTE extends TileEntity implements ITickable{
    	
    	private ItemStackHandler handler = new ItemStackHandler(2);
    	private String customName;
    	public static boolean isOn;
    	public int isOnInt;
    	private int fuelLeft;
    	public int cookTime;
    	
    	@Override
    	public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
    		return (oldState.getBlock() != newState.getBlock());
    	}
    	@Override
    	public void update() {
    		if(!this.world.isRemote) {
    			Campfire.setState(this.world, this.getPos(), this.isBurning());
    			if(this.isOn) {
    				this.isOnInt = 1;
    			} else {
    				this.isOnInt = 0;
    			}
    		}
    	}
    	public boolean isBurning () {
    		return isOnInt > 0;
    	}
    	public void turnOn () {
    		this.isOn = true;
    	}
    	public void turnOff () {
    		this.isOn = false;
    	}
    	public void addFuel (EntityPlayer player) {
    		if(this.fuelLeft + 1000 <= 48000) {
    			this.fuelLeft += 1000;
    			player.sendMessage(new TextComponentString("The fire now has " + this.fuelLeft + " out of 48000 fuel"));
    			if(player.getHeldItem(EnumHand.MAIN_HAND).getCount() > 1) {
    				player.getHeldItem(EnumHand.MAIN_HAND).shrink(1);
    			} else {
    				player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
    			}
    		} else {
    			player.sendMessage(new TextComponentString("The fire is too full to add more logs."));
    		}
    	}
    	@Override
    	public void readFromNBT(NBTTagCompound compound) {
    		super.readFromNBT(compound);
    		this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    		this.cookTime = compound.getInteger("CT");
    		this.isOn = compound.getBoolean("IO");
    		this.isOnInt = compound.getInteger("IOI");
    		if(compound.hasKey("CustomName", 8)) {
    			this.setCustomName(compound.getString("CustomName"));
    		}
    	}
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    		super.writeToNBT(compound);
    		compound.setTag("Inventory", this.handler.serializeNBT());
    		compound.setInteger("CT", (short)this.cookTime);
    		compound.setBoolean("IO", this.isOn);
    		compound.setInteger("IOI", this.isOnInt);
    		if(this.hasCustomName()) {
    			compound.setString("CustomName", this.customName);
    		}
    		return compound;
    	}
    	public boolean hasCustomName () {
    		return this.customName != null && !this.customName.isEmpty();
    	}
    	public void setCustomName(String customName) {
    		this.customName = customName;
    	}
    	@Override
    	public ITextComponent getDisplayName() {
    		return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("Campfire");
    	}
    	
    	public int getField (int id) {
    		switch (id) {
    		case 0:
    			return this.cookTime;
    		default:
    			return 0;
    		}
    	}
    	@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);
    	}
    	
    }
    Posted in: Modification Development
  • 0

    posted a message on Trying to make a block with a tile entity turn light on and off like a furnace.

    I am trying to make a campfire block that emits light and particles when its tile entity value of isonInt is greater than 0, and turn particles and light off if the isOnInt value is 0;


    Here is what I tried:

    The tile entity:



    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.block.Block;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.ITickable;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.util.text.TextComponentTranslation;
    import net.minecraft.world.EnumSkyBlock;
    import net.minecraft.world.World;
    import net.minecraftforge.common.capabilities.Capability;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class CampfireTE extends TileEntity implements ITickable{
    	
    	private ItemStackHandler handler = new ItemStackHandler(2);
    	private String customName;
    	public static boolean isOn;
    	public int isOnInt;
    	private int fuelLeft;
    	public int cookTime;
    	
    	@Override
    	public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
    		if(oldState.getBlock() == ModBlocks.campfire && newState.getBlock() == ModBlocks.lit_campfire) return false;
    		else if (oldState.getBlock() == ModBlocks.lit_campfire && newState.getBlock() == ModBlocks.campfire) return false;
    		return true;
    	}
    	@Override
    	public void update() {
    		if(!this.world.isRemote) {
    			if(this.isOn) {
    				this.isOnInt = 1;
    			} else {
    				this.isOnInt = 0;
    			}
    		}
    	}
    	public boolean isBurning () {
    		return isOnInt > 0;
    	}
    	public void turnOn () {
    		this.isOn = true;
    		Campfire.setState(this.world, this.getPos(), true);
    		this.markDirty();
    	}
    	public void turnOff () {
    		this.isOn = false;
    		Campfire.setState(this.world, this.getPos(), false);
    		this.markDirty();
    	}
    	public void addFuel (EntityPlayer player) {
    		if(this.fuelLeft + 1000 <= 48000) {
    			this.fuelLeft += 1000;
    			player.sendMessage(new TextComponentString("The fire now has " + this.fuelLeft + " out of 48000 fuel"));
    			if(player.getHeldItem(EnumHand.MAIN_HAND).getCount() > 1) {
    				player.getHeldItem(EnumHand.MAIN_HAND).shrink(1);
    			} else {
    				player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
    			}
    		} else {
    			player.sendMessage(new TextComponentString("The fire is too full to add more logs."));
    		}
    	}
    	@Override
    	public void readFromNBT(NBTTagCompound compound) {
    		super.readFromNBT(compound);
    		this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    		this.cookTime = compound.getInteger("CT");
    		this.isOn = compound.getBoolean("IO");
    		this.isOnInt = compound.getInteger("IOI");
    		if(compound.hasKey("CustomName", 8)) {
    			this.setCustomName(compound.getString("CustomName"));
    		}
    	}
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    		super.writeToNBT(compound);
    		compound.setTag("Inventory", this.handler.serializeNBT());
    		compound.setInteger("CT", (short)this.cookTime);
    		compound.setBoolean("IO", this.isOn);
    		compound.setInteger("IOI", this.isOnInt);
    		if(this.hasCustomName()) {
    			compound.setString("CustomName", this.customName);
    		}
    		return compound;
    	}
    	public boolean hasCustomName () {
    		return this.customName != null && !this.customName.isEmpty();
    	}
    	public void setCustomName(String customName) {
    		this.customName = customName;
    	}
    	@Override
    	public ITextComponent getDisplayName() {
    		return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("Campfire");
    	}
    	
    	public int getField (int id) {
    		switch (id) {
    		case 0:
    			return this.cookTime;
    		default:
    			return 0;
    		}
    	}
    	@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);
    	}
    }
    




    The Block:



    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.KennethsMedievalModMain;
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockHorizontal;
    import net.minecraft.block.ITileEntityProvider;
    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.Minecraft;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.Mirror;
    import net.minecraft.util.Rotation;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    public class Campfire extends Block implements ITileEntityProvider {
    	
    	public static final PropertyDirection FACING = BlockHorizontal.FACING;
    	protected String name;
    	protected boolean isOn;
    	
    	public Campfire(String name, boolean isOn) {
    		super(Material.WOOD);
    		setUnlocalizedName(name);
    		setRegistryName(name);
    		setHardness(1);
    		setHardness(1.5F);
    		setResistance(10);
    		setHarvestLevel("axe", 1);
    		setSoundType(SoundType.WOOD);
    		this.isOn = isOn;
    		if(isOn) {
    			setLightLevel(1.0F);
    		}
    		setCreativeTab(CreativeTabs.DECORATIONS);
    	}
    	@Override
    	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    		if(worldIn.isRemote) {
    			return true;
    		} else {
    			TileEntity tileentity = worldIn.getTileEntity(pos);
    			if(tileentity instanceof CampfireTE) {
    				CampfireTE te = (CampfireTE)tileentity;
    				if(playerIn.getHeldItem(EnumHand.MAIN_HAND).getItem() == Item.getItemFromBlock(Blocks.LOG)) {
    					te.addFuel(playerIn);
    				} else {
    					playerIn.openGui(KennethsMedievalModMain.instance, Reference.CAMPFIRE_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
    				}
    			}
    			return true;
    		}
    	}
    	public static void setState (World worldIn, BlockPos pos, boolean active) {
    		IBlockState iblockstate = worldIn.getBlockState(pos);
    	    TileEntity tileentity = worldIn.getTileEntity(pos);
    	    if (active) {
    	        worldIn.setBlockState(pos, ModBlocks.lit_campfire.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    	    } else {
    	        worldIn.setBlockState(pos, ModBlocks.campfire.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    	    }
    	    if (tileentity != null) {
    	        tileentity.validate();
    	        worldIn.setTileEntity(pos, tileentity);
    	    }
    	}
    	@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);
    		}
    	}
    	@Override
    	public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
    		if (this.isOn) {
    			int x = pos.getX();
    			int y = pos.getY();
    			int z = pos.getZ();
    			Block block = this;
    			int i = x;
    			int j = y;
    			int k = z;
    			if (true) {
    				for (int l = 0; l < 5; ++l) {
    					double d0 = (double) ((float) i + 0.6F) + (double) (rand.nextFloat() - 0.5F) * 0.5D;
    					double d1 = ((double) ((float) j + 0.7F) + (double) (rand.nextFloat() - 0.5F) * 0.5D - 0.5F);
    					double d2 = (double) ((float) k + 0.6F) + (double) (rand.nextFloat() - 0.5F) * 0.5D;
    					worldIn.spawnParticle(EnumParticleTypes.FLAME, d0, d1 + 0.2199999988079071D, d2, 0.0D, 0.0D, 0.0D);
    				}
    			}
    		}
    	}
    	@Override
    	public TileEntity createNewTileEntity(World worldIn, int meta) {
    		return new CampfireTE();
    	}
    	@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, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    		if(stack.hasDisplayName()) {
    			TileEntity tileentity = worldIn.getTileEntity(pos);
    			if(tileentity instanceof CampfireTE) {
    				((CampfireTE)tileentity).setCustomName(stack.getDisplayName());
    			}
    		}
    	}
    	@Override
    	public IBlockState getStateFromMeta(int meta) {
    		EnumFacing enumfacing = EnumFacing.getFront(meta);
    		if(enumfacing.getAxis() == EnumFacing.Axis.Y) {
    			enumfacing = EnumFacing.NORTH;
    		}
    		return this.getDefaultState().withProperty(FACING, enumfacing);
    	}
    	@Override
    	public int getMetaFromState(IBlockState state) {
    		return ((EnumFacing)state.getValue(FACING)).getIndex();
    	}
    	@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[] {FACING});
    	}
    	@Override
    	public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
    		return true;
    	}
    	@Override
    	public boolean isOpaqueCube(IBlockState state) {
    		return false;
    	}
    	@Override
    	public boolean isFullBlock(IBlockState state) {
    		return false;
    	}
    }
    





    The mod blocks class:



    package kenneths_mods.kenneths_medieval_mod.objects;
    
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import kenneths_mods.kenneths_medieval_mod.objects.bases.PlanksBase;
    import kenneths_mods.kenneths_medieval_mod.objects.machines.advancedcampfire.AdvancedCampfire;
    import kenneths_mods.kenneths_medieval_mod.objects.machines.campfire.Campfire;
    import kenneths_mods.kenneths_medieval_mod.objects.machines.sawmill.Sawmill;
    import kenneths_mods.kenneths_medieval_mod.objects.trees.ironwood.IronwoodLeaves;
    import kenneths_mods.kenneths_medieval_mod.objects.trees.ironwood.IronwoodLog;
    import kenneths_mods.kenneths_medieval_mod.objects.trees.ironwood.IronwoodSapling;
    import net.minecraft.block.Block;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.client.renderer.block.model.ModelResourceLocation;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemBlock;
    import net.minecraft.util.ResourceLocation;
    import net.minecraftforge.client.model.ModelLoader;
    import net.minecraftforge.fml.common.registry.ForgeRegistries;
    
    public class ModBlocks {
    	
    	public static Block sawmill;
    	public static Block campfire;
    	public static Block lit_campfire;
    	//public static Block advanced_campfire;
    	
    	public static Block planks;
    	
    	public static Block ironwood_log;
    	public static Block ironwood_leaves;
    	public static Block ironwood_sapling;
    	
    	public static void init () {
    		sawmill = new Sawmill();
    		campfire = new Campfire("campfire", false);
    		lit_campfire = new Campfire("lit_campfire", true);
    		//advanced_campfire = new AdvancedCampfire();
    		
    		planks = new PlanksBase ("planks", 3, 25);
    		
    		ironwood_log = new IronwoodLog();
    		ironwood_leaves = new IronwoodLeaves();
    		ironwood_sapling = new IronwoodSapling();
    	}
    	public static void register () {
    		registerBlock(sawmill);
    		registerBlock(campfire);
    		registerBlock(lit_campfire);
    		//registerBlock(advanced_campfire);
    		
    		registerBlockWithVariant(planks, new ItemBlockVariants(planks));
    		
    		registerBlock(ironwood_log);
    		registerBlock(ironwood_leaves);
    		registerBlock(ironwood_sapling);
    	}
    	public static void registerRenders () {
    		registerRender(sawmill);
    		registerRender(campfire);
    		registerRender(lit_campfire);
    		//registerRender(advanced_campfire);
    		
    		registerRender(ironwood_log);
    		registerRender(ironwood_leaves);
    		registerRender(ironwood_sapling);
    	}
    	public static void registerRendersWithVariant () {
    		for(int i = 0; i < PlanksBase.EnumType.values().length; i++) {
    			registerRenderWithVariant(planks, i, "planks_" + PlanksBase.EnumType.values()[i].getName());
    		}
    	}
    	public static void registerBlock (Block block) {
    		ForgeRegistries.BLOCKS.register(block);
    		ForgeRegistries.ITEMS.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
    	}
    	public static void registerBlockWithVariant (Block block, ItemBlock itemBlock) {
    		ForgeRegistries.BLOCKS.register(block);
    		itemBlock.setRegistryName(block.getRegistryName());
    		ForgeRegistries.ITEMS.register(itemBlock);
    	}
    	public static void registerRender (Block block) {
    		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(new ResourceLocation(Reference.MODID, block.getUnlocalizedName().substring(5)), "inventory"));
    	}
    	public static void registerRenderWithVariant (Block block, int meta, String filename) {
    		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(new ResourceLocation(Reference.MODID, filename), "inventory"));
    	}
    }
    



    The GUI:



    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    import org.lwjgl.input.Keyboard;
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.client.gui.GuiButton;
    import net.minecraft.client.gui.inventory.GuiContainer;
    import net.minecraft.client.renderer.GlStateManager;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.Style;
    import net.minecraft.util.text.TextComponentString;
    public class CampfireGUI extends GuiContainer {

    private static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MODID + ":textures/gui/campfire_gui.png");
    private final InventoryPlayer player;
    private final CampfireTE tileentity;

    public CampfireGUI (InventoryPlayer player, CampfireTE tileentity) {
    super(new CampfireContainer(player, tileentity));
    this.player = player;
    this.tileentity = tileentity;
    }
    @Override
    public void updateScreen() {
    super.updateScreen();
    }
    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
    String tileName = this.tileentity.getDisplayName().getUnformattedComponentText();
    this.fontRenderer.drawString(tileName, (this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2) + 3, 8, 4210752);
    this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 122, this.ySize - 96 + 2, 4210752);
    }
    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
    GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
    this.mc.getTextureManager().bindTexture(TEXTURE);
    this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
    }
    @Override
    public void initGui() {
    super.initGui();
    this.guiLeft = (this.width - 176) / 2;
    this.guiTop = (this.height - 166) / 2;
    Keyboard.enableRepeatEvents(true);
    this.buttonList.clear();
    this.buttonList.add(new GuiButton(0, this.guiLeft + 63, this.guiTop + 57, 36, 20, "On/Off"));
    }

    @Override
    protected void actionPerformed(GuiButton button) throws IOException {
    super.actionPerformed(button);
    if(button.id == 0) {
    if(this.tileentity.isOn != true) {
    player.player.sendMessage(new TextComponentString("The fire is now on."));
    this.tileentity.turnOn();
    } else if (this.tileentity.isOn != false) {
    player.player.sendMessage(new TextComponentString("The fire is now off."));
    this.tileentity.turnOff();
    }
    }
    }
    }



    The problem is when I click the on/off button on its gui... it turns on. but when I click on the block it immediately reverts back to the unlit campfire even though I did not click the on/off button again. I have been trying to fix this for over a week with no luck. Can someone please help me?

    Posted in: Modification Development
  • 0

    posted a message on Strange Behaviour from my Sawmill.
    Quote from MadHatAk»

    Are you trying to make basic planks with your sawmill? If so I see your problem.


    1. You're trying to use 2 items in your sawmill to make 1 item. You only have a single input, single output sawmill. It's working like it should. You input the leather, and it returns the arrow.


    One of the problems is that when you empty the output slot it does not take the first available inventory slot. It is very wierd.

    Posted in: Modification Development
  • 0

    posted a message on Making blocks emit particles and light when active?

    Made even more changes. When the player clicks the button on the GUI it turns the fire on by changing it to a lit_campfire block.

    however when the player clicks on the lit_campfire block it instantly reverts back to a regular campfire... anyone know how to fix?


    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.KennethsMedievalModMain;
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import net.minecraft.block.Block;
    import net.minecraft.block.ITileEntityProvider;
    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.state.BlockStateContainer;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.client.Minecraft;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    public class LitCampfire extends Block implements ITileEntityProvider {
    	public LitCampfire() {
    		super(Material.WOOD);
    		setUnlocalizedName("lit_campfire");
    		setRegistryName("lit_campfire");
    		setHardness(1.5F);
    		setResistance(10);
    		setSoundType(SoundType.WOOD);
    		setLightLevel(1.0F);
    	}
    	@Override
    	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    		CampfireTE te = (CampfireTE)worldIn.getTileEntity(pos);
    		if(!worldIn.isRemote) {
    			if(playerIn.getHeldItemMainhand().getItem() == Items.STICK) {
    				te.addFuel(250, playerIn);
    				playerIn.sendMessage(new TextComponentString("The campfire now has " + te.fuelLeft + " out of 5000 in it."));
    			} else {
    				playerIn.openGui(KennethsMedievalModMain.instance, Reference.CAMPFIRE_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
    			}
    		}
    		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
    	}
    	@Override
    	public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random) {
    		CampfireTE te = (CampfireTE)world.getTileEntity(pos);
    		if(te.on == true) {
    			EntityPlayer entity = Minecraft.getMinecraft().player;
    			int x = pos.getX();
    			int y = pos.getY();
    			int z = pos.getZ();
    			Block block = this;
    			int i = x;
    			int j = y;
    			int k = z;
    			if (true) {
    				for (int l = 0; l < 5; ++l) {
    					double d0 = (double) ((float) i + 0.5F) + (double) (random.nextFloat() - 0.5F) * 0.5D;
    					double d1 = ((double) ((float) j + 0.7F) + (double) (random.nextFloat() - 0.5F) * 0.5D) - 0.5D;
    					double d2 = (double) ((float) k + 0.5F) + (double) (random.nextFloat() - 0.5F) * 0.5D;
    					world.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.27000001072883606D, d1 + 0.2199999988079071D, d2, 0.0D, 0.0D, 0.0D);
    				}
    			}
    		}
    	}
    	@Override
    	public boolean hasTileEntity() {
    		return true;
    	}
    	@Override
    	public TileEntity createTileEntity(World world, IBlockState state) {
    		return new CampfireTE();
    	}
    	@Override
    	public TileEntity createNewTileEntity(World worldIn, int meta) {
    		return super.createTileEntity(worldIn, getStateFromMeta(meta));
    	}
    	@Override
    	public boolean isOpaqueCube(IBlockState state) {
    		return false;
    	}
    	@Override
    	public boolean isFullBlock(IBlockState state) {
    		return false;
    	}
    }



    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.KennethsMedievalModMain;
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import net.minecraft.block.Block;
    import net.minecraft.block.ITileEntityProvider;
    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.state.BlockStateContainer;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.client.Minecraft;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    public class Campfire extends Block implements ITileEntityProvider {
     public Campfire() {
     super(Material.WOOD);
     setUnlocalizedName("campfire");
     setRegistryName("campfire");
     setHardness(1.5F);
     setResistance(10);
     setSoundType(SoundType.WOOD);
     setCreativeTab(CreativeTabs.DECORATIONS);
     }
     @Override
     public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
     CampfireTE te = (CampfireTE)worldIn.getTileEntity(pos);
     if(!worldIn.isRemote) {
     if(playerIn.getHeldItemMainhand().getItem() == Items.STICK) {
     te.addFuel(250, playerIn);
     playerIn.sendMessage(new TextComponentString("The campfire now has " + te.fuelLeft + " out of 5000 in it."));
     } else {
     playerIn.openGui(KennethsMedievalModMain.instance, Reference.CAMPFIRE_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
     }
     }
     return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
     }
     @Override
     public boolean hasTileEntity() {
     return true;
     }
     @Override
     public TileEntity createTileEntity(World world, IBlockState state) {
     return new CampfireTE();
     }
     @Override
     public TileEntity createNewTileEntity(World worldIn, int meta) {
     return super.createTileEntity(worldIn, getStateFromMeta(meta));
     }
     @Override
     public boolean isOpaqueCube(IBlockState state) {
     return false;
     }
     @Override
     public boolean isFullBlock(IBlockState state) {
     return false;
     }
    }

    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    
    import org.lwjgl.input.Keyboard;
    
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.client.gui.GuiButton;
    import net.minecraft.client.gui.inventory.GuiContainer;
    import net.minecraft.client.renderer.GlStateManager;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.Style;
    import net.minecraft.util.text.TextComponentString;
    
    public class CampfireGUI extends GuiContainer {
     
     private static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MODID + ":textures/gui/campfire_gui.png");
     private final InventoryPlayer player;
     private final CampfireTE tileentity;
     
     public CampfireGUI (InventoryPlayer player, CampfireTE tileentity) {
     super(new CampfireContainer(player, tileentity));
     this.player = player;
     this.tileentity = tileentity;
     }
     @Override
     public void updateScreen() {
     super.updateScreen();
     }
     @Override
     protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
     String tileName = this.tileentity.getDisplayName().getUnformattedComponentText();
     this.fontRenderer.drawString(tileName, (this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2) + 3, 8, 4210752);
     this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 122, this.ySize - 96 + 2, 4210752);
     }
     @Override
     protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
     GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
     this.mc.getTextureManager().bindTexture(TEXTURE);
     this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
     }
     @Override
     public void initGui() {
     super.initGui();
     this.guiLeft = (this.width - 176) / 2;
     this.guiTop = (this.height - 166) / 2;
     Keyboard.enableRepeatEvents(true);
     this.buttonList.clear();
     this.buttonList.add(new GuiButton(0, this.guiLeft + 63, this.guiTop + 57, 36, 20, "On/Off"));
     }
     
     @Override
     protected void actionPerformed(GuiButton button) throws IOException {
     super.actionPerformed(button);
     if(button.id == 0) {
     if(this.tileentity.on != true) {
     this.tileentity.on = true;
     player.player.sendMessage(new TextComponentString("The fire is now on."));
     this.tileentity.getWorld().setBlockState(this.tileentity.getPos(), ModBlocks.lit_campfire.getDefaultState());
     } else if (this.tileentity.on != false) {
     this.tileentity.on = false;
     player.player.sendMessage(new TextComponentString("The fire is now off."));
     this.tileentity.getWorld().setBlockState(this.tileentity.getPos(), ModBlocks.campfire.getDefaultState());
     }
     }
     }
    }


    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.block.Block;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.ITickable;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.util.text.TextComponentTranslation;
    import net.minecraft.world.EnumSkyBlock;
    import net.minecraft.world.World;
    import net.minecraftforge.common.capabilities.Capability;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class CampfireTE extends TileEntity implements ITickable{
    	
    	private ItemStackHandler handler = new ItemStackHandler(2);
    	private String customName;
    	private int cookTime;
    	public boolean on;
    	public int fuelLeft;
    	@Override
    	public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
    		return false;
    	}
    	@Override
    	public void update() {
    		if(!this.world.isRemote) {
    			if(fuelLeft > 0) {
    				this.fuelLeft--;
    				if(this.handler.getStackInSlot(0) != ItemStack.EMPTY && this.handler.getStackInSlot(1) != ItemStack.EMPTY) {
    					if(!CampfireRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0), this.handler.getStackInSlot(1))) {
    						this.cookTime = 200;
    					}
    				}
    				if(this.handler.getStackInSlot(1).getCount() < this.handler.getStackInSlot(1).getMaxStackSize()) {
    					if(CampfireRecipes.acceptedInputs.contains(this.handler.getStackInSlot(0).copy().getItem())) {
    						this.cookTime--;
    						if(this.handler.getStackInSlot(1) == ItemStack.EMPTY || this.handler.getStackInSlot(1).getCount() == 0) {
    							if(this.cookTime <= 0) {
    								this.handler.setStackInSlot(1, CampfireRecipes.getInstance().getCookingResult(this.handler.getStackInSlot(0)).copy());
    								if(this.handler.getStackInSlot(0).getCount() > 1) {
    									this.handler.getStackInSlot(0).shrink(1);
    								} else {
    									this.handler.setStackInSlot(0, ItemStack.EMPTY);
    								}
    								this.cookTime = 200;
    							}
    						} else {
    							if(CampfireRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0).copy(), this.handler.getStackInSlot(1).copy())) {
    								if(this.cookTime <= 0) {
    									this.handler.getStackInSlot(1).grow(1);
    									if(this.handler.getStackInSlot(0).getCount() > 1) {
    										this.handler.getStackInSlot(0).shrink(1);
    									} else {
    										this.handler.setStackInSlot(0, ItemStack.EMPTY);
    									}
    									this.cookTime = 200;
    								}
    							}
    						}
    					} else {
    						this.cookTime = 200;
    					}
    				}
    			} else {
    				this.cookTime = 200;
    				this.on = false;
    			}
    			markDirty();
    		}
    	}
    	public boolean isOn () {
    		return this.on;
    	}
    	public void addFuel (int toAdd, EntityPlayer player) {
    		if(this.fuelLeft + toAdd < 5000) {
    			this.fuelLeft += toAdd;
    		}
    		if(player.getHeldItemMainhand().getCount() > 1) {
    			player.getHeldItemMainhand().shrink(1);
    		} else {
    			player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
    		}
    	}
    	@Override
    	public void readFromNBT(NBTTagCompound compound) {
    		super.readFromNBT(compound);
    		this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    		this.cookTime = compound.getInteger("CT");
    		this.fuelLeft = compound.getInteger("FL");
    		this.on = compound.getBoolean("O");
    		if(compound.hasKey("CustomName", 8)) {
    			this.setCustomName(compound.getString("CustomName"));
    		}
    	}
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    		super.writeToNBT(compound);
    		compound.setTag("Inventory", this.handler.serializeNBT());
    		compound.setInteger("CT", (short)this.cookTime);
    		compound.setInteger("FL", this.fuelLeft);
    		compound.setBoolean("O", (boolean)this.on);
    		if(this.hasCustomName()) {
    			compound.setString("CustomName", this.customName);
    		}
    		return compound;
    	}
    	public boolean hasCustomName () {
    		return this.customName != null && !this.customName.isEmpty();
    	}
    	public void setCustomName(String customName) {
    		this.customName = customName;
    	}
    	@Override
    	public ITextComponent getDisplayName() {
    		return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("Campfire");
    	}
    	
    	public int getField (int id) {
    		switch (id) {
    		case 0:
    			return this.cookTime;
    		default:
    			return 0;
    		}
    	}
    	@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);
    	}
    }
    Posted in: Modification Development
  • 0

    posted a message on Making blocks emit particles and light when active?

    I have made some changes:


    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.KennethsMedievalModMain;
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import net.minecraft.block.Block;
    import net.minecraft.block.ITileEntityProvider;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.client.Minecraft;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    public class Campfire extends Block implements ITileEntityProvider {
    	public Campfire() {
    		super(Material.WOOD);
    		setUnlocalizedName("campfire");
    		setRegistryName("campfire");
    		setHardness(1.5F);
    		setResistance(10);
    		setSoundType(SoundType.WOOD);
    		setCreativeTab(CreativeTabs.DECORATIONS);
    	}
    	@Override
    	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    		CampfireTE te = (CampfireTE)worldIn.getTileEntity(pos);
    		if(!worldIn.isRemote) {
    			if(playerIn.getHeldItemMainhand().getItem() == Items.STICK) {
    				te.addFuel(250, playerIn);
    				playerIn.sendMessage(new TextComponentString("The campfire now has " + te.fuelLeft + " out of 5000 in it."));
    			} else {
    				playerIn.openGui(KennethsMedievalModMain.instance, Reference.CAMPFIRE_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
    			}
    		}
    		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
    	}
    	@Override
    	public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random) {
    		CampfireTE te = (CampfireTE)world.getTileEntity(pos);
    		if(te.on == true) {
    			EntityPlayer entity = Minecraft.getMinecraft().player;
    			int x = pos.getX();
    			int y = pos.getY();
    			int z = pos.getZ();
    			Block block = this;
    			int i = x;
    			int j = y;
    			int k = z;
    			if (true) {
    				for (int l = 0; l < 5; ++l) {
    					double d0 = (double) ((float) i + 0.5F) + (double) (random.nextFloat() - 0.5F) * 0.5D;
    					double d1 = ((double) ((float) j + 0.7F) + (double) (random.nextFloat() - 0.5F) * 0.5D) - 0.5D;
    					double d2 = (double) ((float) k + 0.5F) + (double) (random.nextFloat() - 0.5F) * 0.5D;
    					world.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.27000001072883606D, d1 + 0.2199999988079071D, d2, 0.0D, 0.0D, 0.0D);
    				}
    			}
    		}
    	}
    	@Override
    	public boolean hasTileEntity() {
    		return true;
    	}
    	@Override
    	public TileEntity createTileEntity(World world, IBlockState state) {
    		return new CampfireTE();
    	}
    	@Override
    	public TileEntity createNewTileEntity(World worldIn, int meta) {
    		return super.createTileEntity(worldIn, getStateFromMeta(meta));
    	}
    	@Override
    	public boolean isOpaqueCube(IBlockState state) {
    		return false;
    	}
    	@Override
    	public boolean isFullBlock(IBlockState state) {
    		return false;
    	}
    }



    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.objects.ModBlocks;
    import net.minecraft.block.Block;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.ITickable;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.util.text.TextComponentTranslation;
    import net.minecraft.world.EnumSkyBlock;
    import net.minecraft.world.World;
    import net.minecraftforge.common.capabilities.Capability;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class CampfireTE extends TileEntity implements ITickable{
    	
    	private ItemStackHandler handler = new  ItemStackHandler(2);
    	private String customName;
    	private int cookTime;
    	public boolean on;
    	public int fuelLeft;
    	
    	@Override
    	public void update() {
    		if(!this.world.isRemote) {
    			if(fuelLeft > 0) {
    				this.fuelLeft--;
    				if(this.handler.getStackInSlot(0) != ItemStack.EMPTY && this.handler.getStackInSlot(1) != ItemStack.EMPTY) {
    					if(!CampfireRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0), this.handler.getStackInSlot(1))) {
    						this.cookTime = 200;
    					}
    				}
    				if(this.handler.getStackInSlot(1).getCount() < this.handler.getStackInSlot(1).getMaxStackSize()) {
    					if(CampfireRecipes.acceptedInputs.contains(this.handler.getStackInSlot(0).copy().getItem())) {
    						this.cookTime--;
    						if(this.handler.getStackInSlot(1) == ItemStack.EMPTY || this.handler.getStackInSlot(1).getCount() == 0) {
    							if(this.cookTime <= 0) {
    								this.handler.setStackInSlot(1, CampfireRecipes.getInstance().getCookingResult(this.handler.getStackInSlot(0)).copy());
    								if(this.handler.getStackInSlot(0).getCount() > 1) {
    									this.handler.getStackInSlot(0).shrink(1);
    								} else {
    									this.handler.setStackInSlot(0, ItemStack.EMPTY);
    								}
    								this.cookTime = 200;
    							}
    						} else {
    							if(CampfireRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0).copy(), this.handler.getStackInSlot(1).copy())) {
    								if(this.cookTime <= 0) {
    									this.handler.getStackInSlot(1).grow(1);
    									if(this.handler.getStackInSlot(0).getCount() > 1) {
    										this.handler.getStackInSlot(0).shrink(1);
    									} else {
    										this.handler.setStackInSlot(0, ItemStack.EMPTY);
    									}
    									this.cookTime = 200;
    								}
    							}
    						}
    					} else {
    						this.cookTime = 200;
    					}
    				}
    			} else {
    				this.cookTime = 200;
    				this.on = false;
    			}
    		}
    	}
    	public void addFuel (int toAdd, EntityPlayer player) {
    		if(this.fuelLeft + toAdd < 5000) {
    			this.fuelLeft += toAdd;
    		}
    		if(player.getHeldItemMainhand().getCount() > 1) {
    			player.getHeldItemMainhand().shrink(1);
    		} else {
    			player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
    		}
    	}
    	@Override
    	public void readFromNBT(NBTTagCompound compound) {
    		super.readFromNBT(compound);
    		this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    		this.cookTime = compound.getInteger("CT");
    		this.fuelLeft = compound.getInteger("FL");
    		this.on = compound.getBoolean("O");
    		if(compound.hasKey("CustomName", 8)) {
    			this.setCustomName(compound.getString("CustomName"));
    		}
    	}
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    		super.writeToNBT(compound);
    		compound.setTag("Inventory", this.handler.serializeNBT());
    		compound.setInteger("CT", (short)this.cookTime);
    		compound.setInteger("FL", this.fuelLeft);
    		compound.setBoolean("O", (boolean)this.on);
    		if(this.hasCustomName()) {
    			compound.setString("CustomName", this.customName);
    		}
    		return compound;
    	}
    	public boolean hasCustomName () {
    		return this.customName != null && !this.customName.isEmpty();
    	}
    	public void setCustomName(String customName) {
    		this.customName = customName;
    	}
    	@Override
    	public ITextComponent getDisplayName() {
    		return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("Campfire");
    	}
    	
    	public int getField (int id) {
    		switch (id) {
    		case 0:
    			return this.cookTime;
    		default:
    			return 0;
    		}
    	}
    	@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);
    	}
    }



    It now only spawns particles when active. The problem is I still can't figure out how to make it emit light only when active. please help. thanks.

    Posted in: Modification Development
  • 0

    posted a message on Making blocks emit particles and light when active?

    I have a campfire that I made that emits light and at the same time emits particles:


    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import kenneths_mods.kenneths_medieval_mod.KennethsMedievalModMain;
    import kenneths_mods.kenneths_medieval_mod.Reference;
    import net.minecraft.block.Block;
    import net.minecraft.block.ITileEntityProvider;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.client.Minecraft;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    public class Campfire extends Block implements ITileEntityProvider {
    	public Campfire() {
    		super(Material.WOOD);
    		setUnlocalizedName("campfire");
    		setRegistryName("campfire");
    		setHardness(1.5F);
    		setResistance(10);
    		setLightLevel(1.0f);
    		setSoundType(SoundType.WOOD);
    		setCreativeTab(CreativeTabs.DECORATIONS);
    	}
    	@Override
    	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    		CampfireTE te = (CampfireTE)worldIn.getTileEntity(pos);
    		if(!worldIn.isRemote) {
    			if(playerIn.getHeldItemMainhand().getItem() == Item.getItemFromBlock(Blocks.LOG)) {
    				te.addFuel(500);
    				if(playerIn.getHeldItemMainhand().getCount() > 1) {
    					playerIn.getHeldItemMainhand().shrink(1);
    				} else {
    					playerIn.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
    				}
    			} else {
    				playerIn.openGui(KennethsMedievalModMain.instance, Reference.CAMPFIRE_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
    			}
    		}
    		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
    	}
    	@Override
    	public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
    		EntityPlayer entity = Minecraft.getMinecraft().player;
    		int x = pos.getX();
    		int y = pos.getY();
    		int z = pos.getZ();
    		Block block = this;
    		int i = x;
    		int j = y;
    		int k = z;
    		if (true) {
    			for (int l = 0; l < 5; ++l) {
    				double d0 = (double) ((float) i + 0.6F) + (double) (rand.nextFloat() - 0.5F) * 0.5D;
    				double d1 = ((double) ((float) j + 0.7F) + (double) (rand.nextFloat() - 0.5F) * 0.5D - 0.5F);
    				double d2 = (double) ((float) k + 0.6F) + (double) (rand.nextFloat() - 0.5F) * 0.5D;
    				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.27000001072883606D, d1 + 0.2199999988079071D, d2, 0.0D, 0.0D, 0.0D);
    			}
    		}
    	}
    	@Override
    	public boolean hasTileEntity() {
    		return true;
    	}
    	@Override
    	public TileEntity createTileEntity(World world, IBlockState state) {
    		return new CampfireTE();
    	}
    	@Override
    	public TileEntity createNewTileEntity(World worldIn, int meta) {
    		return super.createTileEntity(worldIn, getStateFromMeta(meta));
    	}
    	@Override
    	public boolean isOpaqueCube(IBlockState state) {
    		return false;
    	}
    	@Override
    	public boolean isFullBlock(IBlockState state) {
    		return false;
    	}
    }
    



    But I only want it to emit particles and light when the tile entity says it still has fuel:


    package kenneths_mods.kenneths_medieval_mod.objects.machines.campfire;
    
    import java.util.Random;
    
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumParticleTypes;
    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.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class CampfireTE extends TileEntity implements ITickable{
    	
    	private ItemStackHandler handler = new  ItemStackHandler(2);
    	private String customName;
    	private int cookTime;
    	public int fuelLeft;
    	
    	@Override
    	public void update() {
    		if(!this.world.isRemote) {
    			if(fuelLeft > 0) {
    				this.fuelLeft--;
    				if(this.handler.getStackInSlot(0) != ItemStack.EMPTY && this.handler.getStackInSlot(1) != ItemStack.EMPTY) {
    					if(!CampfireRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0), this.handler.getStackInSlot(1))) {
    						this.cookTime = 200;
    					}
    				}
    				if(this.handler.getStackInSlot(1).getCount() < this.handler.getStackInSlot(1).getMaxStackSize()) {
    					if(CampfireRecipes.acceptedInputs.contains(this.handler.getStackInSlot(0).copy().getItem())) {
    						this.cookTime--;
    						if(this.handler.getStackInSlot(1) == ItemStack.EMPTY || this.handler.getStackInSlot(1).getCount() == 0) {
    							if(this.cookTime <= 0) {
    								this.handler.setStackInSlot(1, CampfireRecipes.getInstance().getCookingResult(this.handler.getStackInSlot(0)).copy());
    								if(this.handler.getStackInSlot(0).getCount() > 1) {
    									this.handler.getStackInSlot(0).shrink(1);
    								} else {
    									this.handler.setStackInSlot(0, ItemStack.EMPTY);
    								}
    								this.cookTime = 200;
    							}
    						} else {
    							if(CampfireRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0).copy(), this.handler.getStackInSlot(1).copy())) {
    								if(this.cookTime <= 0) {
    									this.handler.getStackInSlot(1).grow(1);
    									if(this.handler.getStackInSlot(0).getCount() > 1) {
    										this.handler.getStackInSlot(0).shrink(1);
    									} else {
    										this.handler.setStackInSlot(0, ItemStack.EMPTY);
    									}
    									this.cookTime = 200;
    								}
    							}
    						}
    					} else {
    						this.cookTime = 200;
    					}
    				}
    			} else {
    				this.cookTime = 200;
    			}
    		}
    	}
    	public void addFuel (int toAdd) {
    		this.fuelLeft += toAdd;
    	}
    	@Override
    	public void readFromNBT(NBTTagCompound compound) {
    		super.readFromNBT(compound);
    		this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    		this.cookTime = compound.getInteger("CT");
    		this.fuelLeft = compound.getInteger("FL");
    		if(compound.hasKey("CustomName", 8)) {
    			this.setCustomName(compound.getString("CustomName"));
    		}
    	}
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    		super.writeToNBT(compound);
    		compound.setTag("Inventory", this.handler.serializeNBT());
    		compound.setInteger("CT", (short)this.cookTime);
    		compound.setInteger("FL", this.fuelLeft);
    		if(this.hasCustomName()) {
    			compound.setString("CustomName", this.customName);
    		}
    		return compound;
    	}
    	public boolean hasCustomName () {
    		return this.customName != null && !this.customName.isEmpty();
    	}
    	public void setCustomName(String customName) {
    		this.customName = customName;
    	}
    	@Override
    	public ITextComponent getDisplayName() {
    		return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("Campfire");
    	}
    	
    	public int getField (int id) {
    		switch (id) {
    		case 0:
    			return this.cookTime;
    		default:
    			return 0;
    		}
    	}
    	@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);
    	}
    }
    



    Does anyone know what I can do?

    Posted in: Modification Development
  • To post a comment, please .