Jump to content

Recommended Posts

Posted

Pretty simple question,  I have a battery for a custom energy system. I want to have 2 instances of it in the creative tab I made. One that is full, and one that is empty. The values are both stored in NBT. Here is the code:

Tile Entity Class:

package com.harry9137.ct.tileentity;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentText;

public class TileEntityBattery extends TEPowerRelated {
    public int PowerStorageMax = 1000;
    public boolean PowerGen = true;
    public boolean PowerSrc = true;
    public TileEntityBattery(int powerconstructor){
        this.PowerStored = powerconstructor;
    }
    @Override
    public void updateEntity(){
        this.PowerOffering = this.PowerStored;
        this.PowerRequesting = this.PowerStorageMax - this.PowerStored;
       //Don't have a display gui yet, so this is my solution
        Minecraft.getMinecraft().theWorld.getPlayerEntityByName("Harry9137").addChatComponentMessage(new ChatComponentText(Integer.toString(this.PowerStored)));
    }
    @Override
    public void writeToNBT(NBTTagCompound tagCompound) {
        super.writeToNBT(tagCompound);

        tagCompound.setInteger("PowerStored", this.PowerStored);
    }
    @Override
    public void readFromNBT(NBTTagCompound tagCompound){
        super.readFromNBT(tagCompound);
        this.PowerStored = tagCompound.getInteger("PowerStored");
    }
}

TEPowerRelated just is TileEntity with a few values(PowerStored, PowerStorageMax, etc)

 

Block Class:

package com.harry9137.ct.block;

import com.harry9137.ct.CTTab;
import com.harry9137.ct.reference.names;
import com.harry9137.ct.tileentity.TileEntityBattery;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class blockBattery extends blockCT {
    private int PowerStart;
    public blockBattery(int powerconstructor) {
        super(Material.iron);
        this.PowerStart = powerconstructor;
        this.setBlockName(names.blocks.blockBattery);
        this.setCreativeTab(CTTab.CTTab);

    }

    @Override
    public TileEntity createNewTileEntity(World world, int metadata) {
        return new TileEntityBattery(PowerStart);
    }
    @Override
    public boolean hasTileEntity(int meta){
        return true;
    }
}

 

blockCT is just extending Block with a few extra methods

 

Creative Tab Class:

public class CTTab  {
    public static final CreativeTabs CTTab = new CreativeTabs(reference.MOD_ID.toLowerCase()) {
        @Override
        public Item getTabIconItem() {
            return modItems.itemCreepLeaf;
        }


    };
}

 

Main Class:

package com.harry9137.ct;

import com.harry9137.ct.client.gui.GuiHandler;
import com.harry9137.ct.event.EntityDeathEventHooks;
import com.harry9137.ct.event.GameTickEvent;
import com.harry9137.ct.event.PlayerLoginHandler;
import com.harry9137.ct.handler.ConfigurationHandler;
import com.harry9137.ct.init.modBlocks;
import com.harry9137.ct.init.modItems;
import com.harry9137.ct.proxy.IProxy;
import com.harry9137.ct.reference.names;
import com.harry9137.ct.reference.reference;
import com.harry9137.ct.tileentity.TileEntityTechTable;
import com.harry9137.ct.tileentity.TileEntityWire;
import com.harry9137.ct.utillity.LogHelper;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;


@Mod(modid = reference.MOD_ID, name = reference.MOD_NAME, version = reference.MOD_VERSION)
public class CreepTech {

    public static SimpleNetworkWrapper snw;

    @Mod.Instance
    public static CreepTech INSTANCE;

    @SidedProxy(clientSide = reference.CLIENT_PROXY_CLASS, serverSide = reference.SERVER_PROXY_CLASS)
    public static IProxy proxy;

    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event){

        LogHelper.info("Pre-Init Started");


        LogHelper.info("Registering Packet Handler");

      //  snw = NetworkRegistry.INSTANCE.newSimpleChannel(reference.MOD_ID);
      //  snw.registerMessage(PacketHandler.class, WireStatePacket.class, 0, Side.CLIENT);

        LogHelper.info("Registering Events");

        FMLCommonHandler.instance().bus().register(new GameTickEvent());
        MinecraftForge.EVENT_BUS.register(new EntityDeathEventHooks());
        MinecraftForge.EVENT_BUS.register(new PlayerLoginHandler());
        FMLCommonHandler.instance().bus().register(new ConfigurationHandler(event.getSuggestedConfigurationFile()));

        LogHelper.info("Finished Registering Events");

        NetworkRegistry.INSTANCE.registerGuiHandler(this.INSTANCE, new GuiHandler());

        LogHelper.info("Registering Items/Blocks");

        modItems.init();

        modBlocks.init();

        LogHelper.info("Finished Registering Items/Blocks");

        LogHelper.info("Registering Custom Renderers");

        proxy.registerTileRenderers();


        LogHelper.info("Pre-Init Complete");

    }

    @Mod.EventHandler
    public void init(FMLInitializationEvent event){

        LogHelper.info("Init Started");

        LogHelper.info("Registering Tile Entitys");

        GameRegistry.registerTileEntity(TileEntityWire.class, names.blocks.blockWire);
        GameRegistry.registerTileEntity(TileEntityTechTable.class, names.blocks.blockTechTable);

        LogHelper.info("Finished Registering Tile Entitys");

        LogHelper.info("Init Complete");

    }

    @Mod.EventHandler
    public void preInti(FMLPostInitializationEvent event){

        LogHelper.info("Post-Init Started");


        LogHelper.info("Post-Init Complete");

    }
}

Thanks !  :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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

Announcements



×
×
  • Create New...

Important Information

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