ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java

180 lines
5.7 KiB
Java
Raw Normal View History

/*
2016-05-16 22:52:27 +02:00
* This file ("TileEntityAtomicReconstructor.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
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.api.lens.ILensItem;
import de.ellpeck.actuallyadditions.api.lens.Lens;
2017-08-08 21:03:24 +02:00
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
2016-12-06 18:10:43 +01:00
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
2018-08-10 05:04:07 +02:00
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
2016-07-04 20:15:41 +02:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
2016-05-01 22:26:26 +02:00
import net.minecraft.util.SoundCategory;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
2016-01-06 18:10:01 +01:00
import net.minecraft.world.World;
2016-11-26 08:58:42 +01:00
import net.minecraftforge.energy.IEnergyStorage;
public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements IEnergyDisplay, IAtomicReconstructor {
2015-11-15 03:15:19 +01:00
2015-12-09 17:58:20 +01:00
public static final int ENERGY_USE = 1000;
public final CustomEnergyStorage storage;
2016-05-07 02:49:03 +02:00
public int counter;
private int currentTime;
private int oldEnergy;
public TileEntityAtomicReconstructor() {
2015-11-22 18:52:11 +01:00
super(1, "reconstructor");
int power = ConfigIntValues.RECONSTRUCTOR_POWER.getValue();
int recieve = MathHelper.ceil(power * 0.016666F);
storage = new CustomEnergyStorage(power, recieve, 0);
2015-11-22 18:52:11 +01:00
}
public static void shootLaser(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens) {
2016-11-08 20:04:36 +01:00
world.playSound(null, startX, startY, startZ, SoundHandler.reconstructor, SoundCategory.BLOCKS, 0.35F, 1.0F);
AssetUtil.spawnLaserWithTimeServer(world, startX, startY, startZ, endX, endY, endZ, currentLens.getColor(), 25, 0, 0.2F, 0.8F);
2016-05-07 02:49:03 +02:00
}
2016-02-01 17:49:55 +01:00
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
super.writeSyncableNBT(compound, type);
if (type != NBTType.SAVE_BLOCK) {
compound.setInteger("CurrentTime", this.currentTime);
compound.setInteger("Counter", this.counter);
}
2016-02-01 17:49:55 +01:00
this.storage.writeToNBT(compound);
}
@Override
public boolean shouldSyncSlots() {
2016-02-01 17:49:55 +01:00
return true;
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
super.readSyncableNBT(compound, type);
if (type != NBTType.SAVE_BLOCK) {
this.currentTime = compound.getInteger("CurrentTime");
this.counter = compound.getInteger("Counter");
}
2016-02-01 17:49:55 +01:00
this.storage.readFromNBT(compound);
}
@Override
public void updateEntity() {
super.updateEntity();
if (!this.world.isRemote) {
if (!this.isRedstonePowered && !this.isPulseMode) {
if (this.currentTime > 0) {
this.currentTime--;
if (this.currentTime <= 0) {
ActuallyAdditionsAPI.methodHandler.invokeReconstructor(this);
}
} else {
this.currentTime = 100;
}
}
if (this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
this.oldEnergy = this.storage.getEnergyStored();
2017-08-08 21:03:24 +02:00
this.world.updateComparatorOutputLevel(pos, InitBlocks.blockAtomicReconstructor);
}
}
2015-12-03 21:05:45 +01:00
}
@Override
public Lens getLens() {
Item item = inv.getStackInSlot(0).getItem();
if (item instanceof ILensItem) return ((ILensItem) item).getLens();
return this.counter >= 500 ? ActuallyAdditionsAPI.lensDisruption : ActuallyAdditionsAPI.lensDefaultConversion;
}
@Override
public EnumFacing getOrientation() {
IBlockState state = this.world.getBlockState(this.pos);
2018-03-19 16:46:43 +01:00
return WorldUtil.getDirectionByPistonRotation(state);
}
@Override
public BlockPos getPosition() {
return this.pos;
}
@Override
public int getX() {
2016-02-01 17:49:55 +01:00
return this.getPos().getX();
}
@Override
public int getY() {
2016-02-01 17:49:55 +01:00
return this.getPos().getY();
}
@Override
public int getZ() {
2016-02-01 17:49:55 +01:00
return this.getPos().getZ();
2015-12-01 19:48:09 +01:00
}
@Override
public World getWorldObject() {
2016-02-01 17:49:55 +01:00
return this.getWorld();
}
@Override
public void extractEnergy(int amount) {
this.storage.extractEnergyInternal(amount, false);
2016-02-01 17:49:55 +01:00
}
@Override
2018-08-10 05:04:07 +02:00
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> StackUtil.isValid(stack) && stack.getItem() instanceof ILensItem;
2015-11-22 18:52:11 +01:00
}
@Override
public int getEnergy() {
return this.storage.getEnergyStored();
}
@Override
public CustomEnergyStorage getEnergyStorage() {
return this.storage;
}
@Override
public boolean needsHoldShift() {
return false;
}
@Override
public boolean isRedstoneToggle() {
return true;
}
@Override
public void activateOnPulse() {
ActuallyAdditionsAPI.methodHandler.invokeReconstructor(this);
}
2016-11-26 08:58:42 +01:00
@Override
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
2016-11-26 08:58:42 +01:00
return this.storage;
}
}