Added modular battery
This commit is contained in:
parent
7eaf73341b
commit
ee2dc80248
7 changed files with 285 additions and 1 deletions
|
@ -6,6 +6,7 @@ itemGroup.resonantinduction=Resonant Induction
|
|||
tile.resonantinduction\:tesla.name=Tesla Coil
|
||||
tile.resonantinduction\:multimeter.name=Multimeter
|
||||
tile.resonantinduction\:contractor.name=Electromagnetic Contractor
|
||||
tile.resonantinduction\:battery.name=Modular Battery
|
||||
|
||||
## Items
|
||||
item.resonantinduction\:quantumEntangler.name=Quantum Entangler
|
|
@ -9,6 +9,8 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import resonantinduction.battery.BlockBattery;
|
||||
import resonantinduction.battery.TileEntityBattery;
|
||||
import resonantinduction.contractor.BlockEMContractor;
|
||||
import resonantinduction.contractor.ItemBlockContractor;
|
||||
import resonantinduction.contractor.TileEntityEMContractor;
|
||||
|
@ -112,6 +114,7 @@ public class ResonantInduction
|
|||
public static Block blockTesla;
|
||||
public static Block blockMultimeter;
|
||||
public static Block blockEMContractor;
|
||||
public static Block blockBattery;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent evt)
|
||||
|
@ -138,17 +141,20 @@ public class ResonantInduction
|
|||
blockTesla = new BlockTesla(getNextBlockID());
|
||||
blockMultimeter = new BlockMultimeter(getNextBlockID());
|
||||
blockEMContractor = new BlockEMContractor(getNextBlockID());
|
||||
blockBattery = new BlockBattery(getNextBlockID());
|
||||
|
||||
CONFIGURATION.save();
|
||||
|
||||
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(blockMultimeter, ItemBlockMultimeter.class, blockMultimeter.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(blockBattery, blockBattery.getUnlocalizedName());
|
||||
|
||||
// Tiles
|
||||
GameRegistry.registerTileEntity(TileEntityTesla.class, blockTesla.getUnlocalizedName());
|
||||
GameRegistry.registerTileEntity(TileEntityMultimeter.class, blockMultimeter.getUnlocalizedName());
|
||||
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
|
||||
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
|
||||
|
||||
ResonantInduction.proxy.registerRenderers();
|
||||
|
||||
|
|
23
src/resonantinduction/battery/BatteryController.java
Normal file
23
src/resonantinduction/battery/BatteryController.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction.battery;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Multiblock battery controller
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class BatteryController
|
||||
{
|
||||
public Set<TileEntityBattery> connectedBlocks = new HashSet<TileEntityBattery>();
|
||||
|
||||
public void update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
81
src/resonantinduction/battery/BlockBattery.java
Normal file
81
src/resonantinduction/battery/BlockBattery.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction.battery;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.ResonantInduction;
|
||||
import resonantinduction.base.BlockBase;
|
||||
import resonantinduction.multimeter.TileEntityMultimeter;
|
||||
|
||||
/**
|
||||
* A block that detects power.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||
{
|
||||
private Icon machineIcon;
|
||||
|
||||
public BlockBattery(int id)
|
||||
{
|
||||
super("battery", id, Material.iron);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(int side, int metadata)
|
||||
{
|
||||
if (side == metadata)
|
||||
{
|
||||
return this.blockIcon;
|
||||
}
|
||||
|
||||
return this.machineIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IconRegister iconRegister)
|
||||
{
|
||||
super.registerIcons(iconRegister);
|
||||
this.machineIcon = iconRegister.registerIcon(ResonantInduction.PREFIX + "machine");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9)
|
||||
{
|
||||
if (entityPlayer.isSneaking())
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.ROTATION_MATRIX[world.getBlockMetadata(x, y, z)][side], 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world)
|
||||
{
|
||||
return new TileEntityBattery();
|
||||
}
|
||||
}
|
167
src/resonantinduction/battery/TileEntityBattery.java
Normal file
167
src/resonantinduction/battery/TileEntityBattery.java
Normal file
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction.battery;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import resonantinduction.base.TileEntityBase;
|
||||
|
||||
/**
|
||||
* A modular battery with no GUI.
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
public class TileEntityBattery extends TileEntityBase implements IInventory
|
||||
{
|
||||
private ItemStack[] inventory = new ItemStack[4 * 4];
|
||||
private byte[] sideStatus = new byte[] { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
//TODO: Multiblock power storage.
|
||||
private BatteryController controller;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public float getMaxEnergyStored()
|
||||
{
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of slots in the inventory.
|
||||
*/
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.inventory.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stack in slot i
|
||||
*/
|
||||
public ItemStack getStackInSlot(int par1)
|
||||
{
|
||||
return this.inventory[par1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes from an inventory slot (first arg) up to a specified number (second arg) of items and
|
||||
* returns them in a new stack.
|
||||
*/
|
||||
public ItemStack decrStackSize(int par1, int par2)
|
||||
{
|
||||
if (this.inventory[par1] != null)
|
||||
{
|
||||
ItemStack itemstack;
|
||||
|
||||
if (this.inventory[par1].stackSize <= par2)
|
||||
{
|
||||
itemstack = this.inventory[par1];
|
||||
this.inventory[par1] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemstack = this.inventory[par1].splitStack(par2);
|
||||
|
||||
if (this.inventory[par1].stackSize == 0)
|
||||
{
|
||||
this.inventory[par1] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When some containers are closed they call this on each slot, then drop whatever it returns as
|
||||
* an EntityItem - like when you close a workbench GUI.
|
||||
*/
|
||||
public ItemStack getStackInSlotOnClosing(int par1)
|
||||
{
|
||||
if (this.inventory[par1] != null)
|
||||
{
|
||||
ItemStack itemstack = this.inventory[par1];
|
||||
this.inventory[par1] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor
|
||||
* sections).
|
||||
*/
|
||||
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
|
||||
{
|
||||
this.inventory[par1] = par2ItemStack;
|
||||
|
||||
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
|
||||
{
|
||||
par2ItemStack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInvName()
|
||||
{
|
||||
return this.getBlockType().getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvNameLocalized()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.minecraft.inventory.IInventory#openChest()
|
||||
*/
|
||||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -115,7 +115,7 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider
|
|||
@Override
|
||||
public boolean canProvidePower()
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,6 +49,7 @@ public class TileEntityMultimeter extends TileEntityBase implements IPacketRecei
|
|||
|
||||
if (this.ticks % 20 == 0)
|
||||
{
|
||||
float prevDetectedEnergy = this.detectedEnergy;
|
||||
this.detectedEnergy = this.doGetDetectedEnergy();
|
||||
this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2;
|
||||
|
||||
|
@ -80,6 +81,11 @@ public class TileEntityMultimeter extends TileEntityBase implements IPacketRecei
|
|||
this.redstoneOn = outputRedstone;
|
||||
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, ResonantInduction.blockMultimeter.blockID);
|
||||
}
|
||||
|
||||
/*
|
||||
* if (prevDetectedEnergy != this.detectedEnergy) {
|
||||
* this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); }
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue