2015-09-30 21:03:43 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityLeafGenerator.java") is part of the Actually Additions mod for Minecraft.
|
2015-09-30 21:03:43 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-09-30 21:03:43 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-09-30 21:03:43 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-09-30 21:03:43 +02:00
|
|
|
|
|
|
|
import cofh.api.energy.EnergyStorage;
|
2016-06-05 12:15:02 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
2016-06-15 16:43:59 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2015-09-30 21:03:43 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-09-30 21:03:43 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2016-03-18 23:47:22 +01:00
|
|
|
import java.util.List;
|
2015-09-30 21:03:43 +02:00
|
|
|
|
2016-08-31 20:16:36 +02:00
|
|
|
public class TileEntityLeafGenerator extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay{
|
2015-09-30 21:03:43 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
public static final int RANGE = 7;
|
|
|
|
public static final int ENERGY_PRODUCED = 300;
|
2016-05-19 20:05:12 +02:00
|
|
|
public final EnergyStorage storage = new EnergyStorage(35000);
|
2015-09-30 21:03:43 +02:00
|
|
|
private int nextUseCounter;
|
2015-12-21 22:18:33 +01:00
|
|
|
private int oldEnergy;
|
2015-09-30 21:03:43 +02:00
|
|
|
|
2016-05-06 23:23:29 +02:00
|
|
|
public TileEntityLeafGenerator(){
|
|
|
|
super("leafGenerator");
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
}
|
|
|
|
|
2015-09-30 21:03:43 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2016-05-02 17:46:53 +02:00
|
|
|
if(!this.worldObj.isRemote){
|
2015-12-03 18:40:43 +01:00
|
|
|
if(!this.isRedstonePowered){
|
2015-10-05 11:27:53 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
if(this.nextUseCounter >= 5){
|
2015-10-05 11:27:53 +02:00
|
|
|
this.nextUseCounter = 0;
|
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
if(ENERGY_PRODUCED <= this.storage.getMaxEnergyStored()-this.storage.getEnergyStored()){
|
2016-03-18 23:47:22 +01:00
|
|
|
List<BlockPos> breakPositions = new ArrayList<BlockPos>();
|
2015-10-05 11:27:53 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
for(int reachX = -RANGE; reachX < RANGE+1; reachX++){
|
|
|
|
for(int reachZ = -RANGE; reachZ < RANGE+1; reachZ++){
|
|
|
|
for(int reachY = -RANGE; reachY < RANGE+1; reachY++){
|
2016-07-04 20:15:41 +02:00
|
|
|
BlockPos pos = this.pos.add(reachX, reachY, reachZ);
|
|
|
|
Block block = this.worldObj.getBlockState(pos).getBlock();
|
2016-03-18 23:47:22 +01:00
|
|
|
if(block != null && block.isLeaves(this.worldObj.getBlockState(pos), this.worldObj, pos)){
|
2016-01-07 21:41:28 +01:00
|
|
|
breakPositions.add(pos);
|
2015-10-05 11:27:53 +02:00
|
|
|
}
|
2015-09-30 21:03:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 11:27:53 +02:00
|
|
|
if(!breakPositions.isEmpty()){
|
|
|
|
Collections.shuffle(breakPositions);
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos theCoord = breakPositions.get(0);
|
2015-09-30 21:03:43 +02:00
|
|
|
|
2016-06-05 12:15:02 +02:00
|
|
|
if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){
|
2016-06-03 21:05:49 +02:00
|
|
|
this.worldObj.playEvent(2001, theCoord, Block.getStateId(this.worldObj.getBlockState(theCoord)));
|
2016-01-23 11:02:35 +01:00
|
|
|
}
|
2015-09-30 21:03:43 +02:00
|
|
|
|
2016-01-08 15:21:05 +01:00
|
|
|
this.worldObj.setBlockToAir(theCoord);
|
2015-09-30 21:03:43 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
this.storage.receiveEnergy(ENERGY_PRODUCED, false);
|
2015-12-16 20:54:50 +01:00
|
|
|
|
2016-06-05 12:15:02 +02:00
|
|
|
if(!ConfigBoolValues.LESS_PARTICLES.isEnabled()){
|
2016-08-03 04:01:47 +02:00
|
|
|
AssetUtil.shootParticles(this.worldObj, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), theCoord.getX(), theCoord.getY(), theCoord.getZ(), new float[]{62F/255F, 163F/255F, 74F/255F}, 5, 1.0F, 1F);
|
2016-01-23 11:02:35 +01:00
|
|
|
}
|
2015-10-05 11:27:53 +02:00
|
|
|
}
|
2015-09-30 21:03:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-05 11:27:53 +02:00
|
|
|
else{
|
|
|
|
this.nextUseCounter++;
|
|
|
|
}
|
2015-09-30 21:03:43 +02:00
|
|
|
}
|
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
|
|
|
this.oldEnergy = this.storage.getEnergyStored();
|
|
|
|
}
|
2015-09-30 21:03:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public int extractEnergy(EnumFacing from, int maxReceive, boolean simulate){
|
2015-09-30 21:03:43 +02:00
|
|
|
return this.storage.extractEnergy(maxReceive, simulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public int getEnergyStored(EnumFacing from){
|
2015-09-30 21:03:43 +02:00
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
2015-09-30 21:03:43 +02:00
|
|
|
return this.storage.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public boolean canConnectEnergy(EnumFacing from){
|
2015-09-30 21:03:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-13 00:54:25 +01:00
|
|
|
|
|
|
|
@Override
|
2016-07-21 13:22:55 +02:00
|
|
|
public EnergyStorage getEnergyStorage(){
|
|
|
|
return this.storage;
|
2015-12-13 00:54:25 +01:00
|
|
|
}
|
2016-07-02 18:39:47 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean needsHoldShift(){
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-31 20:16:36 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyToSplitShare(){
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean doesShareEnergy(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing[] getEnergyShareSides(){
|
|
|
|
return EnumFacing.values();
|
|
|
|
}
|
2015-09-30 21:03:43 +02:00
|
|
|
}
|