2015-11-14 21:27:36 +01:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityAtomicReconstructor.java") is part of the Actually Additions mod for Minecraft.
|
2015-11-14 21:27:36 +01: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-11-14 21:27:36 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-11-14 21:27:36 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2016-05-15 12:00:42 +02:00
|
|
|
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;
|
2018-02-17 22:08:40 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
2016-12-06 18:10:43 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
2016-06-15 16:43:59 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2018-08-10 05:04:07 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2018-06-23 01:39:30 +02:00
|
|
|
import net.minecraft.item.Item;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.util.Direction;
|
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;
|
2018-02-17 22:08:40 +01:00
|
|
|
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;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2018-06-23 01:39:30 +02:00
|
|
|
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;
|
2018-02-17 22:08:40 +01:00
|
|
|
public final CustomEnergyStorage storage;
|
2016-05-07 02:49:03 +02:00
|
|
|
public int counter;
|
2015-11-14 21:27:36 +01:00
|
|
|
private int currentTime;
|
2015-12-21 22:18:33 +01:00
|
|
|
private int oldEnergy;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2018-06-23 01:39:30 +02:00
|
|
|
public TileEntityAtomicReconstructor() {
|
2015-11-22 18:52:11 +01:00
|
|
|
super(1, "reconstructor");
|
2018-02-17 22:08:40 +01:00
|
|
|
int power = ConfigIntValues.RECONSTRUCTOR_POWER.getValue();
|
|
|
|
int recieve = MathHelper.ceil(power * 0.016666F);
|
2019-02-27 19:53:05 +01:00
|
|
|
this.storage = new CustomEnergyStorage(power, recieve, 0);
|
2015-11-22 18:52:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-23 01:39:30 +02: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);
|
2016-12-09 21:36:43 +01:00
|
|
|
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
|
2021-02-26 22:15:48 +01:00
|
|
|
public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
|
2016-07-02 15:01:46 +02:00
|
|
|
super.writeSyncableNBT(compound, type);
|
2018-06-23 01:39:30 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
compound.setInteger("CurrentTime", this.currentTime);
|
|
|
|
compound.setInteger("Counter", this.counter);
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public boolean shouldSyncSlots() {
|
2016-02-01 17:49:55 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void readSyncableNBT(CompoundNBT compound, NBTType type) {
|
2016-07-02 15:01:46 +02:00
|
|
|
super.readSyncableNBT(compound, type);
|
2018-06-23 01:39:30 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
this.currentTime = compound.getInteger("CurrentTime");
|
|
|
|
this.counter = compound.getInteger("Counter");
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
}
|
|
|
|
|
2015-11-14 21:27:36 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public void updateEntity() {
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2018-06-23 01:39:30 +02:00
|
|
|
if (!this.world.isRemote) {
|
|
|
|
if (!this.isRedstonePowered && !this.isPulseMode) {
|
|
|
|
if (this.currentTime > 0) {
|
2015-11-14 23:05:20 +01:00
|
|
|
this.currentTime--;
|
2018-06-23 01:39:30 +02:00
|
|
|
if (this.currentTime <= 0) {
|
2017-02-20 13:19:19 +01:00
|
|
|
ActuallyAdditionsAPI.methodHandler.invokeReconstructor(this);
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|
2018-06-23 01:39:30 +02:00
|
|
|
} else {
|
2015-11-28 19:02:01 +01:00
|
|
|
this.currentTime = 100;
|
2015-11-14 23:05:20 +01:00
|
|
|
}
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|
2015-12-21 22:18:33 +01:00
|
|
|
|
2018-06-23 01:39:30 +02:00
|
|
|
if (this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
|
2015-12-21 22:18:33 +01:00
|
|
|
this.oldEnergy = this.storage.getEnergyStored();
|
2019-02-27 19:53:05 +01:00
|
|
|
this.world.updateComparatorOutputLevel(this.pos, InitBlocks.blockAtomicReconstructor);
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|
2015-12-03 21:05:45 +01:00
|
|
|
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-05-14 14:14:06 +02:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public Lens getLens() {
|
2019-02-27 19:53:05 +01:00
|
|
|
Item item = this.inv.getStackInSlot(0).getItem();
|
2021-02-26 22:15:48 +01:00
|
|
|
if (item instanceof ILensItem) {
|
|
|
|
return ((ILensItem) item).getLens();
|
|
|
|
}
|
|
|
|
return this.counter >= 500
|
|
|
|
? ActuallyAdditionsAPI.lensDisruption
|
|
|
|
: ActuallyAdditionsAPI.lensDefaultConversion;
|
2015-11-15 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
2016-12-03 13:29:20 +01:00
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public Direction getOrientation() {
|
2021-02-26 22:15:48 +01:00
|
|
|
BlockState state = this.world.getBlockState(this.pos);
|
2018-03-19 16:46:43 +01:00
|
|
|
return WorldUtil.getDirectionByPistonRotation(state);
|
2016-12-03 13:29:20 +01:00
|
|
|
}
|
|
|
|
|
2017-02-20 13:19:19 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public BlockPos getPosition() {
|
2017-02-20 13:19:19 +01:00
|
|
|
return this.pos;
|
|
|
|
}
|
|
|
|
|
2015-11-14 21:27:36 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public int getX() {
|
2016-02-01 17:49:55 +01:00
|
|
|
return this.getPos().getX();
|
2016-01-11 22:41:33 +01:00
|
|
|
}
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2016-02-01 17:43:14 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public int getY() {
|
2016-02-01 17:49:55 +01:00
|
|
|
return this.getPos().getY();
|
2016-02-01 17:43:14 +01:00
|
|
|
}
|
|
|
|
|
2016-01-11 22:41:33 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public int getZ() {
|
2016-02-01 17:49:55 +01:00
|
|
|
return this.getPos().getZ();
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2015-11-14 21:27:36 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public World getWorldObject() {
|
2016-02-01 17:49:55 +01:00
|
|
|
return this.getWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public void extractEnergy(int amount) {
|
2016-12-03 12:26:45 +01:00
|
|
|
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
|
|
|
}
|
2015-12-13 00:54:25 +01:00
|
|
|
|
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public int getEnergy() {
|
2015-12-13 00:54:25 +01:00
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public CustomEnergyStorage getEnergyStorage() {
|
2016-07-21 13:22:55 +02:00
|
|
|
return this.storage;
|
2015-12-13 00:54:25 +01:00
|
|
|
}
|
2015-12-18 16:22:39 +01:00
|
|
|
|
2016-07-02 18:39:47 +02:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public boolean needsHoldShift() {
|
2016-07-02 18:39:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-18 16:22:39 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public boolean isRedstoneToggle() {
|
2016-07-02 15:01:46 +02:00
|
|
|
return true;
|
2015-12-18 16:22:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public void activateOnPulse() {
|
2017-02-20 13:19:19 +01:00
|
|
|
ActuallyAdditionsAPI.methodHandler.invokeReconstructor(this);
|
2015-12-18 16:22:39 +01:00
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public IEnergyStorage getEnergyStorage(Direction facing) {
|
2016-11-26 08:58:42 +01:00
|
|
|
return this.storage;
|
|
|
|
}
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|