Now stores eu when broken with a wrench. Added empty and full ones to creative tab.
This commit is contained in:
parent
63fa58eb24
commit
af9e9e535a
3 changed files with 134 additions and 3 deletions
|
@ -233,7 +233,7 @@ public class ModBlocks {
|
||||||
GameRegistry.registerBlock(Idsu, "idsu");
|
GameRegistry.registerBlock(Idsu, "idsu");
|
||||||
|
|
||||||
Aesu = new BlockAesu(Material.rock);
|
Aesu = new BlockAesu(Material.rock);
|
||||||
GameRegistry.registerBlock(Aesu, "aesu");
|
GameRegistry.registerBlock(Aesu, ItemBlockAesu.class, "aesu");
|
||||||
GameRegistry.registerTileEntity(TileAesu.class, "TileAesuTR");
|
GameRegistry.registerTileEntity(TileAesu.class, "TileAesuTR");
|
||||||
|
|
||||||
Lesu = new BlockLesu(Material.rock);
|
Lesu = new BlockLesu(Material.rock);
|
||||||
|
|
92
src/main/java/techreborn/itemblocks/ItemBlockAesu.java
Normal file
92
src/main/java/techreborn/itemblocks/ItemBlockAesu.java
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
package techreborn.itemblocks;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import ic2.api.item.ElectricItem;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import techreborn.init.ModBlocks;
|
||||||
|
import techreborn.tiles.TileAesu;
|
||||||
|
import techreborn.tiles.TileQuantumChest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ItemBlockAesu extends ItemBlock {
|
||||||
|
|
||||||
|
public ItemBlockAesu(Block p_i45328_1_)
|
||||||
|
{
|
||||||
|
super(p_i45328_1_);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings(
|
||||||
|
{ "rawtypes", "unchecked" })
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public void addInformation(ItemStack stack, EntityPlayer player, List list,
|
||||||
|
boolean par4)
|
||||||
|
{
|
||||||
|
if (stack != null && stack.hasTagCompound())
|
||||||
|
{
|
||||||
|
if (stack.getTagCompound().getCompoundTag("tileEntity") != null)
|
||||||
|
list.add(stack.getTagCompound().getCompoundTag("tileEntity")
|
||||||
|
.getDouble("energy")
|
||||||
|
+ " eu");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean placeBlockAt(ItemStack stack, EntityPlayer player,
|
||||||
|
World world, int x, int y, int z, int side, float hitX, float hitY,
|
||||||
|
float hitZ, int metadata)
|
||||||
|
{
|
||||||
|
if (!world.setBlock(x, y, z, ModBlocks.Aesu, metadata, 3))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (world.getBlock(x, y, z) == ModBlocks.Aesu)
|
||||||
|
{
|
||||||
|
world.getBlock(x, y, z).onBlockPlacedBy(world, x, y, z, player,
|
||||||
|
stack);
|
||||||
|
world.getBlock(x, y, z).onPostBlockPlaced(world, x, y, z, metadata);
|
||||||
|
}
|
||||||
|
if (stack != null && stack.hasTagCompound())
|
||||||
|
{
|
||||||
|
((TileAesu) world.getTileEntity(x, y, z))
|
||||||
|
.readFromNBTWithoutCoords(stack.getTagCompound()
|
||||||
|
.getCompoundTag("tileEntity"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings(
|
||||||
|
{ "rawtypes", "unchecked" })
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList){
|
||||||
|
itemList.add(getDropWithNBT(0));
|
||||||
|
itemList.add(getDropWithNBT(1000000000));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getDropWithNBT(double energy)
|
||||||
|
{
|
||||||
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||||
|
ItemStack dropStack = new ItemStack(ModBlocks.Aesu, 1);
|
||||||
|
writeToNBTWithoutCoords(tileEntity, energy);
|
||||||
|
dropStack.setTagCompound(new NBTTagCompound());
|
||||||
|
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
|
||||||
|
return dropStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound, double energy)
|
||||||
|
{
|
||||||
|
tagCompound.setDouble("energy", energy);
|
||||||
|
tagCompound.setDouble("euChange", 0);
|
||||||
|
tagCompound.setDouble("euLastTick", 0);
|
||||||
|
tagCompound.setBoolean("active", false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
package techreborn.tiles;
|
package techreborn.tiles;
|
||||||
|
|
||||||
|
import ic2.api.energy.EnergyNet;
|
||||||
import ic2.api.tile.IWrenchable;
|
import ic2.api.tile.IWrenchable;
|
||||||
import ic2.core.block.wiring.TileEntityElectricBlock;
|
import ic2.core.block.wiring.TileEntityElectricBlock;
|
||||||
|
import ic2.core.util.Util;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
|
@ -33,18 +36,26 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
|
||||||
if(ticks == ConfigTechReborn.aveargeEuOutTickTime){
|
if(ticks == ConfigTechReborn.aveargeEuOutTickTime){
|
||||||
euChange = -1;
|
euChange = -1;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ticks ++;
|
ticks ++;
|
||||||
euChange += energy - euLastTick;
|
euChange += energy - euLastTick;
|
||||||
|
if(euLastTick == energy){
|
||||||
|
euChange = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
euLastTick = energy;
|
euLastTick = energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
|
||||||
{
|
{
|
||||||
|
if(!entityPlayer.isSneaking()){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getFacing()
|
public short getFacing()
|
||||||
|
@ -78,7 +89,7 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
|
||||||
{
|
{
|
||||||
return new ItemStack(ModBlocks.Aesu, 1);
|
return getDropWithNBT();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isComplete()
|
public boolean isComplete()
|
||||||
|
@ -133,5 +144,33 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
|
||||||
return (euChange / ticks);
|
return (euChange / ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemStack getDropWithNBT()
|
||||||
|
{
|
||||||
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||||
|
ItemStack dropStack = new ItemStack(ModBlocks.Aesu, 1);
|
||||||
|
writeToNBTWithoutCoords(tileEntity);
|
||||||
|
dropStack.setTagCompound(new NBTTagCompound());
|
||||||
|
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
|
||||||
|
return dropStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound)
|
||||||
|
{
|
||||||
|
tagCompound.setDouble("energy", this.energy);
|
||||||
|
tagCompound.setDouble("euChange", euChange);
|
||||||
|
tagCompound.setDouble("euLastTick", euLastTick);
|
||||||
|
tagCompound.setBoolean("active", this.getActive());
|
||||||
|
tagCompound.setByte("redstoneMode", this.redstoneMode);
|
||||||
|
inventory.writeToNBT(tagCompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromNBTWithoutCoords(NBTTagCompound nbttagcompound) {
|
||||||
|
this.energy = Util.limit(nbttagcompound.getDouble("energy"), 0.0D, (double) this.maxStorage + EnergyNet.instance.getPowerFromTier(this.tier));
|
||||||
|
this.redstoneMode = nbttagcompound.getByte("redstoneMode");
|
||||||
|
this.euChange = nbttagcompound.getDouble("euChange");
|
||||||
|
this.euLastTick = nbttagcompound.getDouble("euLastTick");
|
||||||
|
inventory.readFromNBT(nbttagcompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue