Jump to content

Euan

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by Euan

  1. Thanks man. that was it. Completely forgot to do that
  2. Hey guys, I'm confused. I'm trying to add a model to my mod (which I've done before successfully) and when placing it places an empty block ( or null according to the debug f3 stuff) instead of the model. I've no idea what's going on because the model renders in the hand of the player fine. So here's the codes. Block Electric Furnace package com.euan.newage.tech.blocks; import java.util.Random; import com.euan.newage.tech.Main; import com.euan.newage.tech.blocks.entities.TileEntityElectricFurnace; import com.euan.newage.tech.util.Reference; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; public class BlockElectricFurnace extends BlockTileEntity<TileEntityElectricFurnace> { public static final PropertyDirection FACING = BlockHorizontal.FACING; public static final PropertyBool BURNING = PropertyBool.create("burning"); public BlockElectricFurnace() { super(Material.ROCK, "machine_electric_furnace", Main.mainTab, "machineElectricFurnace"); setSoundType(SoundType.METAL); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false)); } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(ModBlocks.electricFurnace); } @Override public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(ModBlocks.electricFurnace); } @SideOnly(Side.CLIENT) public void initModel() { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory")); } @Override @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) { return false; } @Override public boolean isNormalCube(IBlockState state) { return false; } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public TileEntityElectricFurnace createTileEntity(World world, IBlockState state) { return new TileEntityElectricFurnace(); } @Override public Class<TileEntityElectricFurnace> getTileEntityClass() { return TileEntityElectricFurnace.class; } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { player.openGui(Main.instance, Reference.GUI_ELECTRIC_FURNACE, world, pos.getX(), pos.getY(), pos.getZ()); } return true; } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState north = worldIn.getBlockState(pos.north()); IBlockState south = worldIn.getBlockState(pos.south()); IBlockState west = worldIn.getBlockState(pos.west()); IBlockState east = worldIn.getBlockState(pos.east()); EnumFacing face = (EnumFacing)state.getValue(FACING); if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH; else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH; else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST; else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST; worldIn.setBlockState(pos, state.withProperty(FACING, face), 2); } } public static void setState(boolean active, World worldIn, BlockPos pos) { IBlockState state = worldIn.getBlockState(pos); TileEntity tileentity = worldIn.getTileEntity(pos); if(active) worldIn.setBlockState(pos, ModBlocks.electricFurnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, true), 3); else worldIn.setBlockState(pos, ModBlocks.electricFurnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, false), 3); if(tileentity != null) { tileentity.validate(); worldIn.setTileEntity(pos, tileentity); } } @Override public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2); } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } @Override public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING))); } @Override public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING))); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {BURNING,FACING}); } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing facing = EnumFacing.getFront(meta); if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH; return this.getDefaultState().withProperty(FACING, facing); } @Override public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getIndex(); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityElectricFurnace) { TileEntityElectricFurnace te = (TileEntityElectricFurnace)tileentity; InventoryHelper.dropInventoryItems(worldIn, pos, te.getIInventory()); worldIn.updateComparatorOutputLevel(pos, this); } } } TileEntityElectricFurnace package com.euan.newage.tech.blocks.entities; import java.io.Console; import javax.annotation.Nullable; import javax.swing.plaf.basic.BasicComboBoxUI.ItemHandler; import com.euan.newage.tech.blocks.BlockElectricFurnace; import com.euan.newage.tech.blocks.BlockHydraulicPress; import com.euan.newage.tech.items.ModItems; import com.euan.newage.tech.util.recipes.HydraulicPressRecipes; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryBasic; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemTool; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; public class TileEntityElectricFurnace extends TileEntity implements ITickable { public ItemStackHandler handler = new ItemStackHandler(2); private int currentBurningTime; private int burningTime = 200; private boolean isBurning = false; @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; else return false; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) this.handler; return super.getCapability(capability, facing); } @Override public ITextComponent getDisplayName() { return new TextComponentTranslation("tile.machine_electric_furnace"); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.handler.deserializeNBT(compound.getCompoundTag("Inventory")); this.currentBurningTime = compound.getInteger("CurrentBurningTime"); this.burningTime = compound.getInteger("BurningTime"); this.isBurning = compound.getBoolean("isBurning"); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("CurrentBurningTime", (short) this.currentBurningTime); compound.setInteger("BurningTime", (short) this.burningTime); compound.setTag("Inventory", this.handler.serializeNBT()); compound.setBoolean("isBurning", isBurning); return compound; } @Override public void update() { ItemStack enter = this.handler.getStackInSlot(0); if (enter.isEmpty()) { stopBurning(); return; } ItemStack result = this.handler.getStackInSlot(1); ItemStack enterRe = new ItemStack(enter.getItem()); enterRe.setCount(1); enterRe = HydraulicPressRecipes.getInstance().getResult(enterRe); if (enterRe.equals(ItemStack.EMPTY) || (result.isEmpty() == false && sameItem(enterRe, result) == false)) { stopBurning(); return; } if(!canAddToStack(result, enterRe)) { stopBurning(); return; } if (currentBurningTime >= burningTime) { if (result.isEmpty()) { this.handler.setStackInSlot(1, enterRe); } else { int count = this.handler.getStackInSlot(1).getCount() + enterRe.getCount(); this.handler.getStackInSlot(1).setCount(count); } this.handler.getStackInSlot(0).setCount(this.handler.getStackInSlot(0).getCount() - 1); stopBurning(); return; } if (isBurning == false && currentBurningTime == 0) { if (!enterRe.equals(ItemStack.EMPTY)) { startBurning(); } } currentBurningTime++; } private void startBurning() { isBurning = true; BlockElectricFurnace.setState(isBurning, getWorld(), getPos()); } private void stopBurning() { if (isBurning == true) { isBurning = false; currentBurningTime = 0; BlockElectricFurnace.setState(isBurning, getWorld(), getPos()); } } public IInventory getIInventory() { InventoryBasic basic = new InventoryBasic("", false, 2); basic.setInventorySlotContents(0, handler.getStackInSlot(0)); basic.setInventorySlotContents(1, handler.getStackInSlot(1)); return basic; } private boolean sameItem(ItemStack itemStack, ItemStack itemStack2) { return itemStack.getItem().equals(itemStack2.getItem()); } private boolean canAddToStack(ItemStack itemStack, ItemStack itemStack2) { return itemStack.getCount() + itemStack2.getCount() <= itemStack.getMaxStackSize(); } public int getField(int id) { switch (id) { case 0: return burningTime; case 1: return currentBurningTime; default: return 0; } } public void setField(int id, int value) { switch (id) { case 0: burningTime = value; break; case 1: currentBurningTime = value; break; default: break; } } public boolean isUsableByPlayer(EntityPlayer player) { return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double) this.pos.getX() + 0.5D, (double) this.pos.getY() + 0.5D, (double) this.pos.getZ() + 0.5D) <= 64.0D; } } Here's where I'm registering the entity public static void register(IForgeRegistry<Block> registry) { registry.registerAll(oreCopper, oreTin, oreSilver, oreSilicon, oreGarnet, oreSaphire, oreRuby, hydraulicPress); GameRegistry.registerTileEntity(hydraulicPress.getTileEntityClass(), hydraulicPress.getRegistryName().toString()); GameRegistry.registerTileEntity(electricFurnace.getTileEntityClass(), electricFurnace.getRegistryName().toString()); } public static void registerItemBlocks(IForgeRegistry<Item> registry) { registry.registerAll(oreCopper.createItemBlock(), oreTin.createItemBlock(), oreSilver.createItemBlock(), oreSilicon.createItemBlock(), oreGarnet.createItemBlock(), oreSaphire.createItemBlock(), oreRuby.createItemBlock(), hydraulicPress.createItemBlock(), electricFurnace.createItemBlock()); } public static void registerModels() { oreCopper.registerItemModel(Item.getItemFromBlock(oreCopper)); oreTin.registerItemModel(Item.getItemFromBlock(oreTin)); oreSilver.registerItemModel(Item.getItemFromBlock(oreSilver)); oreSilicon.registerItemModel(Item.getItemFromBlock(oreSilicon)); oreGarnet.registerItemModel(Item.getItemFromBlock(oreGarnet)); oreSaphire.registerItemModel(Item.getItemFromBlock(oreSaphire)); oreRuby.registerItemModel(Item.getItemFromBlock(oreRuby)); hydraulicPress.registerItemModel(Item.getItemFromBlock(hydraulicPress)); electricFurnace.registerItemModel(Item.getItemFromBlock(electricFurnace)); } the registerItemModel and createItemBlock methods should be working because they're working for all the other blocks (including the hydraulic press which is another modeled block). Any ideas?
  3. I know tinkers construct publishes its source and has custom, I may not be able to help you but comparer yours to its and you might find something. If not try looking for other mods that do the same.
  4. Is there an easier way to do this? Because I already have the system set up, it's merely getting the integers to be saved and read.
  5. Unfortunately I'm not at my pc at the moment but if my memory serves me correctly then you get a position with the block. Things inside the cave I believe are decided at the very end of the generation of the cave so you'll be able to check the blocks around the block being spawned using a sub method of World (or maybe in the generator?). From that you can spawn it according to the conditions. As for the setting a priority to which orientation it would simply require an else if block. Then in the order you want check to make sure that the side you want orientated is stone and the majority of the other sides have air next to it.
  6. How I would do it is check to make sure that only on of the blocks connecting to the crystal is stone and the rest air. The orientate the block depending on which block is stone. If you want it to be able to be placed when there are other blocks to its side then choose an order to check where there are blocks connected to it and have its orientation set depending on which is the first block in the order to be there.
  7. I'm creating a custom leveling system for tools. So the player has top be a certain level in a skill to use certain items. The exp and levels need to be stored.
  8. Basically I'm trying to save some ints.
  9. Hey guys, I'm trying to figure out how to save data. I've read the info on the documentation and else where (from older versions) and so very little has helped. So how should I go about saving the data? I Understand I should use WorldSavedData (or a custom class extending it) to do it but I'm not sure how to work with NBTTags or NBTTagCompounds or getting the classed called while the game is saving and being loaded. Any help or links to how this can be done would be much appreciated.
  10. Alright brilliant, thanks mate
  11. And I can subscribe to them yeah?
  12. Hey guys, I'm trying to get a method called every time the player right or left clicks on any tool in the game. So I was wondering is there an event that gets called everytime time the player clicks?
×
×
  • Create New...

Important Information

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