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;
|
2022-05-18 22:39:49 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.AASounds;
|
2021-02-28 11:35:10 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
2022-01-19 02:11:23 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
|
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-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;
|
2022-09-02 01:26:54 +02:00
|
|
|
import net.minecraft.state.properties.BlockStateProperties;
|
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;
|
2022-09-02 01:26:54 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
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;
|
2021-02-27 16:33:00 +01:00
|
|
|
import net.minecraftforge.common.util.LazyOptional;
|
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;
|
2021-02-27 16:33:00 +01:00
|
|
|
public final LazyOptional<IEnergyStorage> lazyEnergy;
|
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;
|
2022-02-12 17:27:49 +01:00
|
|
|
private int ttl = 0;
|
|
|
|
private int maxAge = 0;
|
2022-07-27 20:06:26 +02:00
|
|
|
private int beamColor = 0x1b6dff;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2018-06-23 01:39:30 +02:00
|
|
|
public TileEntityAtomicReconstructor() {
|
2021-08-31 00:44:39 +02:00
|
|
|
super(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getTileEntityType(), 1);
|
2022-03-13 20:29:06 +01:00
|
|
|
int power = CommonConfig.Machines.RECONSTRUCTOR_POWER.get();
|
2018-02-17 22:08:40 +01:00
|
|
|
int recieve = MathHelper.ceil(power * 0.016666F);
|
2019-02-27 19:53:05 +01:00
|
|
|
this.storage = new CustomEnergyStorage(power, recieve, 0);
|
2021-02-27 16:33:00 +01:00
|
|
|
this.lazyEnergy = LazyOptional.of(() -> this.storage);
|
2015-11-22 18:52:11 +01:00
|
|
|
}
|
|
|
|
|
2022-02-12 17:27:49 +01:00
|
|
|
public static void shootLaser(IAtomicReconstructor tile, World world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens) {
|
2022-05-18 22:39:49 +02:00
|
|
|
world.playSound(null, startX, startY, startZ, AASounds.RECONSTRUCTOR.get(), 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
|
|
|
}
|
|
|
|
|
2022-09-02 01:26:54 +02:00
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getRenderBoundingBox() {
|
|
|
|
if (getProgress() > 0.0f)
|
|
|
|
return new AxisAlignedBB(getPosition(), getPosition().offset(1,1,1).relative(getBlockState().getValue(BlockStateProperties.FACING), 11));
|
|
|
|
else
|
|
|
|
return super.getRenderBoundingBox();
|
|
|
|
}
|
|
|
|
|
2022-02-12 17:27:49 +01:00
|
|
|
@Override
|
|
|
|
public int getTTL() {
|
|
|
|
return this.ttl;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resetBeam(int maxAge) {
|
2022-07-27 20:06:26 +02:00
|
|
|
this.resetBeam(maxAge, 0x1b6dff);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resetBeam(int maxAge, int color) {
|
2022-02-12 17:27:49 +01:00
|
|
|
this.ttl = maxAge;
|
|
|
|
this.maxAge = maxAge;
|
2022-07-27 20:06:26 +02:00
|
|
|
this.beamColor = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBeamColor() {
|
|
|
|
return this.beamColor;
|
2022-02-12 17:27:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public float getProgress(){
|
|
|
|
if (maxAge > 0)
|
|
|
|
return (float)ttl / (float)maxAge;
|
|
|
|
else
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void decTTL() {
|
|
|
|
if (this.ttl > 0)
|
|
|
|
this.ttl--;
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-02-27 16:33:00 +01:00
|
|
|
compound.putInt("CurrentTime", this.currentTime);
|
|
|
|
compound.putInt("Counter", this.counter);
|
2016-07-02 15:01:46 +02:00
|
|
|
}
|
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) {
|
2021-02-27 16:33:00 +01:00
|
|
|
this.currentTime = compound.getInt("CurrentTime");
|
|
|
|
this.counter = compound.getInt("Counter");
|
2016-07-02 15:01:46 +02:00
|
|
|
}
|
2022-10-13 00:49:01 +02:00
|
|
|
if (compound.contains("Energy"))
|
|
|
|
this.storage.readFromNBT(compound);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
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();
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!this.level.isClientSide) {
|
2018-06-23 01:39:30 +02:00
|
|
|
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();
|
2021-08-22 17:09:06 +02:00
|
|
|
this.level.updateNeighbourForOutputSignal(this.worldPosition, ActuallyBlocks.ATOMIC_RECONSTRUCTOR.get());
|
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();
|
|
|
|
}
|
2022-06-24 21:23:43 +02:00
|
|
|
return 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-08-22 17:09:06 +02:00
|
|
|
BlockState state = this.level.getBlockState(this.worldPosition);
|
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() {
|
2021-08-22 17:09:06 +02:00
|
|
|
return this.worldPosition;
|
2017-02-20 13:19:19 +01:00
|
|
|
}
|
|
|
|
|
2015-11-14 21:27:36 +01:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public int getX() {
|
2021-08-22 17:09:06 +02:00
|
|
|
return this.getBlockPos().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() {
|
2021-08-22 17:09:06 +02:00
|
|
|
return this.getBlockPos().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() {
|
2021-08-22 17:09:06 +02:00
|
|
|
return this.getBlockPos().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() {
|
2021-08-22 17:09:06 +02:00
|
|
|
return this.getLevel();
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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() {
|
2022-01-19 02:11:23 +01:00
|
|
|
return (slot, stack, automation) -> !stack.isEmpty() && 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 16:33:00 +01:00
|
|
|
public LazyOptional<IEnergyStorage> getEnergyStorage(Direction facing) {
|
|
|
|
return this.lazyEnergy;
|
2016-11-26 08:58:42 +01:00
|
|
|
}
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|