package com.thebrokenrail.energonrelics.block.entity.forcefield.laser; import com.thebrokenrail.energonrelics.EnergonRelics; import com.thebrokenrail.energonrelics.block.entity.forcefield.FieldProjectorBlockEntity; import com.thebrokenrail.energonrelics.block.forcefield.laser.IndustrialLaserProjectorBlock; import com.thebrokenrail.energonrelics.config.HardcodedConfig; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.nbt.CompoundTag; import net.minecraft.particle.ParticleTypes; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.explosion.Explosion; public class IndustrialLaserBlockEntity extends FieldProjectorBlockEntity { private BlockPos targetPos; private BlockState targetState; private int progress = 0; public IndustrialLaserBlockEntity(BlockEntityType type) { super(type, state -> EnergonRelics.INDUSTRIAL_LASER_BLOCK); } @Override protected void setLastBlock(BlockPos newPos, BlockState newState) { if (!newPos.equals(targetPos) || targetState != newState) { targetPos = newPos; targetState = newState; progress = 0; } } @Override protected long getCost() { return HardcodedConfig.INDUSTRIAL_LASER_ENERGY_REQUIRED; } @Override protected void energyTick() { super.energyTick(); if (getCachedState().get(IndustrialLaserProjectorBlock.POWERED) && targetState != null && targetPos != null && IndustrialLaserRegistry.has(targetState.getBlock())) { assert getWorld() != null; if (progress >= HardcodedConfig.INDUSTRIAL_LASER_BEAM_TIME) { getWorld().createExplosion(null, targetPos.getX() + 0.5d, targetPos.getY() + 0.5d, targetPos.getZ() + 0.5d, 0.5f, Explosion.DestructionType.NONE); Block.dropStack(getWorld(), targetPos, IndustrialLaserRegistry.get(targetState.getBlock(), getWorld().random)); getWorld().breakBlock(targetPos, false); progress = 0; } else { Vec3d vec = Vec3d.ofCenter(targetPos); ((ServerWorld) getWorld()).spawnParticles(ParticleTypes.FLAME, vec.getX(), vec.getY(), vec.getZ(), 1, 0.3f, 0.3f, 0.3f, 0f); progress++; } markDirty(); } else if (progress != 0) { progress = 0; markDirty(); } } @Override public CompoundTag toTag(CompoundTag tag) { super.toTag(tag); tag.putInt("Progress", progress); return tag; } @Override public void fromTag(BlockState state, CompoundTag tag) { super.fromTag(state, tag); progress = tag.getInt("Progress"); } }