Skip to content

Commit

Permalink
Finished battery box render and GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGuardsman committed Mar 28, 2018
1 parent 5f439bf commit ff14573
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 33 deletions.
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
Expand All @@ -24,7 +25,13 @@ public class BlockBattery extends BlockICBM
{
public BlockBattery()
{
super("batteryBox", Material.WOOD);
super("batterybox", Material.WOOD);
}

@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}

@Override
Expand All @@ -42,27 +49,24 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
{
((TileEntityBattery) tileEntity).getInventory().transferIntoInventory(playerIn, hand, heldStack);
}
return true;
}
else if (heldStack.getItem() == Items.STICK)
{
if (!worldIn.isRemote)
{
int slotInUse = ((TileEntityBattery) tileEntity).getInventory().getSlots() - ((TileEntityBattery) tileEntity).getInventory().getEmptySlots().size();
int energy = ((TileEntityBattery) tileEntity).getEnergyStorage().getEnergyStored();
playerIn.sendMessage(new TextComponentString("Batteries: " + slotInUse + " " + energy));
playerIn.sendMessage(new TextComponentString("Batteries: " + slotInUse + " Energy: " + energy));
}
return true;
}
return false;
}
else
{
//TODO open GUI
((TileEntityBattery) tileEntity).openGui(playerIn, 0);
}
}

return false;
return true;
}

@Nullable
Expand Down
@@ -1,9 +1,25 @@
package icbm.classic.content.machines.battery;

import icbm.classic.prefab.gui.ContainerBase;
import icbm.classic.prefab.gui.slot.SlotEnergyItem;
import net.minecraft.entity.player.EntityPlayer;

/**
* @see <a href="https://github.com/BuiltBrokenModding/VoltzEngine/blob/development/license.md">License</a> for what you can and can't do with the code.
* Created by Dark(DarkGuardsman, Robert) on 3/28/2018.
*/
public class ContainerBattery
public class ContainerBattery extends ContainerBase<TileEntityBattery>
{
public ContainerBattery(EntityPlayer player, TileEntityBattery node)
{
super(player, node);
int x = 50;
int y = 50;
for (int slot = 0; slot < TileEntityBattery.SLOTS; slot++)
{
this.addSlotToContainer(new SlotEnergyItem(node.getInventory(), slot, slot * 18 + x, y));
}

addPlayerInventory(player);
}
}
@@ -1,9 +1,27 @@
package icbm.classic.content.machines.battery;

import icbm.classic.prefab.gui.GuiContainerBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;

/**
* @see <a href="https://github.com/BuiltBrokenModding/VoltzEngine/blob/development/license.md">License</a> for what you can and can't do with the code.
* Created by Dark(DarkGuardsman, Robert) on 3/28/2018.
*/
public class GuiBattery
public class GuiBattery extends GuiContainerBase
{
public GuiBattery(EntityPlayer player, TileEntityBattery battery)
{
super(new ContainerBattery(player, battery));
}

@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
for(Slot slot : inventorySlots.inventorySlots)
{
drawSlot(slot);
}
}
}
Expand Up @@ -103,13 +103,23 @@ public IESIterator(IItemHandler inventory)
@Override
public boolean hasNext()
{
while (get(nextSlot) == null)
while (get(nextSlot) == null && insideLimits())
{
nextSlot++;
}
return isNextValid();
}

private boolean insideLimits()
{
return nextSlot >= 0 && nextSlot < inventory.getSlots();
}

private boolean isNextValid()
{
return insideLimits() && get(nextSlot) != null;
}

@Override
public IEnergyStorage next()
{
Expand Down
@@ -1,7 +1,10 @@
package icbm.classic.content.machines.battery;

import icbm.classic.ICBMClassic;
import icbm.classic.lib.IGuiTile;
import icbm.classic.prefab.inventory.ExternalInventory;
import icbm.classic.prefab.inventory.IInventoryProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
Expand All @@ -15,7 +18,7 @@
* @see <a href="https://github.com/BuiltBrokenModding/VoltzEngine/blob/development/license.md">License</a> for what you can and can't do with the code.
* Created by Dark(DarkGuardsman, Robert) on 3/21/2018.
*/
public class TileEntityBattery extends TileEntity implements IInventoryProvider
public class TileEntityBattery extends TileEntity implements IInventoryProvider, IGuiTile
{
public static final int SLOTS = 5;

Expand Down Expand Up @@ -69,4 +72,23 @@ else if (capability == CapabilityEnergy.ENERGY)
}
return getCapability(capability, facing);
}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player)
{
return new ContainerBattery(player, this);
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player)
{
return new GuiBattery(player, this);
}

@Override
public boolean openGui(EntityPlayer player, int requestedID)
{
player.openGui(ICBMClassic.INSTANCE, requestedID, world, getPos().getX(), getPos().getY(), getPos().getZ());
return true;
}
}
26 changes: 4 additions & 22 deletions src/main/resources/assets/icbmclassic/blockstates/batterybox.json
@@ -1,33 +1,15 @@
{
"forge_marker": 1,
"defaults": {
"model": "cube_all",
"textures": {
"particle": "blocks/anvil_base",
"down": "blocks/planks_big_oak",
"up": "blocks/planks_big_oak",
"north": "blocks/anvil_base",
"east": "blocks/anvil_base",
"south": "blocks/anvil_base",
"west": "blocks/anvil_base"
}
"model": "icbmclassic:batterybox"
},
"variants": {
"normal": [
{}
],
"inventory": [
{}
],
"normal": {
"model": "cube_all",
"textures": {
"particle": "blocks/anvil_base",
"down": "blocks/planks_big_oak",
"up": "blocks/planks_big_oak",
"north": "blocks/anvil_base",
"east": "blocks/anvil_base",
"south": "blocks/anvil_base",
"west": "blocks/anvil_base"
}
},
"rotation": {
"up": {},
"down": {},
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/assets/icbmclassic/models/block/batterybox.json
@@ -0,0 +1,12 @@
{
"parent": "block/cube_all",
"textures": {
"particle": "minecraft:blocks/anvil_base",
"down": "minecraft:blocks/planks_big_oak",
"up": "minecraft:blocks/planks_big_oak",
"north": "minecraft:blocks/anvil_base",
"east": "minecraft:blocks/anvil_base",
"south": "minecraft:blocks/anvil_base",
"west": "minecraft:blocks/anvil_base"
}
}

0 comments on commit ff14573

Please sign in to comment.