Made Blocks store their energy when broken

This commit is contained in:
Ellpeck 2015-12-13 00:54:25 +01:00
parent 3ee78080f3
commit 4282329699
18 changed files with 241 additions and 16 deletions

View file

@ -12,6 +12,7 @@ package ellpeck.actuallyadditions.blocks.base;
import cpw.mods.fml.common.registry.GameRegistry;
import ellpeck.actuallyadditions.creative.CreativeTab;
import ellpeck.actuallyadditions.tile.IEnergySaver;
import ellpeck.actuallyadditions.tile.TileEntityBase;
import ellpeck.actuallyadditions.tile.TileEntityInventoryBase;
import ellpeck.actuallyadditions.util.ModUtil;
@ -19,7 +20,9 @@ import ellpeck.actuallyadditions.util.Util;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.EnumRarity;
@ -28,6 +31,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import java.util.ArrayList;
public abstract class BlockContainerBase extends BlockContainer{
private String name;
@ -126,4 +131,46 @@ public abstract class BlockContainerBase extends BlockContainer{
((TileEntityBase)tile).setRedstonePowered(world.isBlockIndirectlyGettingPowered(x, y, z));
}
}
@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player){
if(!player.capabilities.isCreativeMode){
this.dropBlockAsItem(world, x, y, z, meta, 0);
}
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
TileEntity tile = world.getTileEntity(x, y, z);
if(tile != null){
ItemStack stack = new ItemStack(this.getItemDropped(metadata, Util.RANDOM, fortune), 1, this.damageDropped(metadata));
if(tile instanceof IEnergySaver){
int energy = ((IEnergySaver)tile).getEnergy();
if(energy > 0){
if(stack.getTagCompound() == null){
stack.setTagCompound(new NBTTagCompound());
}
stack.getTagCompound().setInteger("Energy", energy);
}
}
drops.add(stack);
}
return drops;
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack){
if(stack.getTagCompound() != null){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof IEnergySaver){
((IEnergySaver)tile).setEnergy(stack.getTagCompound().getInteger("Energy"));
}
}
}
}

View file

@ -0,0 +1,18 @@
/*
* This file ("IEnergySaver.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.tile;
public interface IEnergySaver{
int getEnergy();
void setEnergy(int energy);
}

View file

@ -24,7 +24,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements IEnergyReceiver{
public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver{
public static final int ENERGY_USE = 1000;
public EnergyStorage storage = new EnergyStorage(3000000);
@ -149,4 +149,14 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
public boolean canExtractItem(int slot, ItemStack stack, int side){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -24,7 +24,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
public class TileEntityCanolaPress extends TileEntityInventoryBase implements IEnergyReceiver, IFluidHandler{
public class TileEntityCanolaPress extends TileEntityInventoryBase implements IEnergyReceiver, IFluidHandler, IEnergySaver{
public static final int PRODUCE = 100;
public static final int ENERGY_USE = 35;
@ -188,4 +188,14 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
public FluidTankInfo[] getTankInfo(ForgeDirection from){
return new FluidTankInfo[]{this.tank.getInfo()};
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -20,7 +20,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityCoalGenerator extends TileEntityInventoryBase implements IEnergyProvider{
public class TileEntityCoalGenerator extends TileEntityInventoryBase implements IEnergyProvider, IEnergySaver{
public static final int PRODUCE = 30;
public EnergyStorage storage = new EnergyStorage(60000);
@ -148,4 +148,14 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
public boolean canConnectEnergy(ForgeDirection from){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -25,7 +25,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, IEnergyReceiver, IFluidHandler{
public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, IEnergyReceiver, IFluidHandler, IEnergySaver{
public static final int SLOT_COFFEE_BEANS = 0;
public static final int SLOT_INPUT = 1;
@ -231,4 +231,14 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
public FluidTankInfo[] getTankInfo(ForgeDirection from){
return new FluidTankInfo[]{this.tank.getInfo()};
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -24,7 +24,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implements IEnergyReceiver{
public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver{
public static final int RANGE = 8;
public static final int ENERGY_USE = 5;
@ -134,4 +134,14 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
public boolean canConnectEnergy(ForgeDirection from){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -19,7 +19,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityEnergizer extends TileEntityInventoryBase implements IEnergyReceiver{
public class TileEntityEnergizer extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver{
public EnergyStorage storage = new EnergyStorage(500000);
private int lastEnergy;
@ -104,4 +104,14 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements IEne
public boolean canConnectEnergy(ForgeDirection from){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -20,7 +20,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityEnervator extends TileEntityInventoryBase implements IEnergyProvider{
public class TileEntityEnervator extends TileEntityInventoryBase implements IEnergyProvider, IEnergySaver{
public EnergyStorage storage = new EnergyStorage(500000);
private int lastEnergy;
@ -114,4 +114,14 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne
public boolean canExtractItem(int slot, ItemStack stack, int side){
return slot == 1;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -19,7 +19,7 @@ import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements IEnergyReceiver{
public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver{
public static final int SLOT_INPUT_1 = 0;
public static final int SLOT_OUTPUT_1 = 1;
@ -193,4 +193,14 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
public boolean canConnectEnergy(ForgeDirection from){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -16,7 +16,7 @@ import ellpeck.actuallyadditions.util.WorldUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyProvider{
public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyProvider, IEnergySaver{
public static final int PRODUCE = 10;
public EnergyStorage storage = new EnergyStorage(30000);
@ -80,4 +80,14 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyPro
}
return false;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -23,7 +23,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.List;
public class TileEntityGrinder extends TileEntityInventoryBase implements IEnergyReceiver{
public class TileEntityGrinder extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver{
public static final int SLOT_INPUT_1 = 0;
public static final int SLOT_OUTPUT_1_1 = 1;
@ -241,6 +241,16 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IEnerg
return slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
public static class TileEntityGrinderDouble extends TileEntityGrinder{
public TileEntityGrinderDouble(){

View file

@ -22,7 +22,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
public class TileEntityHeatCollector extends TileEntityBase implements IEnergyProvider{
public class TileEntityHeatCollector extends TileEntityBase implements IEnergyProvider, IEnergySaver{
public static final int ENERGY_PRODUCE = 40;
public static final int BLOCKS_NEEDED = 4;
@ -90,4 +90,14 @@ public class TileEntityHeatCollector extends TileEntityBase implements IEnergyPr
public boolean canConnectEnergy(ForgeDirection from){
return from == ForgeDirection.UP;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -18,7 +18,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityItemRepairer extends TileEntityInventoryBase implements IEnergyReceiver{
public class TileEntityItemRepairer extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver{
public static final int SLOT_INPUT = 0;
public static final int SLOT_OUTPUT = 1;
@ -128,4 +128,14 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase implements I
public boolean canConnectEnergy(ForgeDirection from){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -19,7 +19,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyReceiver{
public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyReceiver, IEnergySaver{
public static final int NOT_MULTI = 0;
public static final int HAS_LAVA = 1;
@ -92,4 +92,14 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I
public boolean canConnectEnergy(ForgeDirection from){
return from != ForgeDirection.UP;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -21,7 +21,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
import java.util.Collections;
public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyProvider{
public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyProvider, IEnergySaver{
public static final int RANGE = 7;
public static final int ENERGY_PRODUCED = 300;
@ -111,4 +111,14 @@ public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyPr
public boolean canConnectEnergy(ForgeDirection from){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -28,7 +28,7 @@ import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyReceiver, IButtonReactor{
public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyReceiver, IButtonReactor, IEnergySaver{
public EnergyStorage storage = new EnergyStorage(1000000);
public static final int ENERGY_USE_PER_BLOCK = 500;
@ -177,4 +177,14 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyR
this.layerAt = -1;
}
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}

View file

@ -21,7 +21,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
public class TileEntityOilGenerator extends TileEntityInventoryBase implements IEnergyProvider, IFluidHandler{
public class TileEntityOilGenerator extends TileEntityInventoryBase implements IEnergyProvider, IFluidHandler, IEnergySaver{
public static final int ENERGY_PRODUCED = 76;
private static final int BURN_TIME = 100;
@ -186,4 +186,14 @@ public class TileEntityOilGenerator extends TileEntityInventoryBase implements I
public FluidTankInfo[] getTankInfo(ForgeDirection from){
return new FluidTankInfo[]{this.tank.getInfo()};
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
}