This commit is contained in:
parent
1740c58262
commit
6fcb8f675d
@ -35,6 +35,8 @@ public class FieldProjectorBlockEntity extends EnergyReceiverBlockEntity {
|
||||
if (getCachedState().get(FieldProjectorBlock.POWERED)) {
|
||||
Direction facing = getCachedState().get(FieldProjectorBlock.FACING);
|
||||
BlockState state = block.apply(getCachedState()).getDefaultState().with(AbstractFieldBlock.FACING, facing);
|
||||
|
||||
boolean valid = false;
|
||||
for (int i = 1; i < HardcodedConfig.FIELD_MAX_SIZE + 1; i++) {
|
||||
BlockPos targetPos = getPos().offset(facing, i);
|
||||
BlockState targetState = getWorld().getBlockState(targetPos);
|
||||
@ -42,9 +44,13 @@ public class FieldProjectorBlockEntity extends EnergyReceiverBlockEntity {
|
||||
getWorld().setBlockState(targetPos, state);
|
||||
} else if (targetState != state) {
|
||||
setLastBlock(targetPos, targetState);
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
setLastBlock(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import com.thebrokenrail.energonrelics.block.forcefield.laser.IndustrialLaserPro
|
||||
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.TntBlock;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
@ -14,6 +16,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class IndustrialLaserBlockEntity extends FieldProjectorBlockEntity {
|
||||
private BlockPos targetPos;
|
||||
private BlockState targetState;
|
||||
@ -26,7 +30,7 @@ public class IndustrialLaserBlockEntity extends FieldProjectorBlockEntity {
|
||||
|
||||
@Override
|
||||
protected void setLastBlock(BlockPos newPos, BlockState newState) {
|
||||
if (!newPos.equals(targetPos) || targetState != newState) {
|
||||
if (!Objects.equals(newPos, targetPos) || targetState != newState) {
|
||||
targetPos = newPos;
|
||||
targetState = newState;
|
||||
progress = 0;
|
||||
@ -42,9 +46,17 @@ public class IndustrialLaserBlockEntity extends FieldProjectorBlockEntity {
|
||||
protected void energyTick() {
|
||||
super.energyTick();
|
||||
|
||||
if (getCachedState().get(IndustrialLaserProjectorBlock.POWERED) && targetState != null && targetPos != null && IndustrialLaserRegistry.has(targetState.getBlock())) {
|
||||
if (getCachedState().get(IndustrialLaserProjectorBlock.POWERED) && targetState != null && targetPos != null) {
|
||||
assert getWorld() != null;
|
||||
|
||||
if (targetState.getBlock() == Blocks.TNT) {
|
||||
TntBlock.primeTnt(getWorld(), targetPos);
|
||||
getWorld().setBlockState(targetPos, Blocks.AIR.getDefaultState());
|
||||
|
||||
progress = 0;
|
||||
|
||||
markDirty();
|
||||
} else if (IndustrialLaserRegistry.has(targetState.getBlock())) {
|
||||
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));
|
||||
@ -54,12 +66,13 @@ public class IndustrialLaserBlockEntity extends FieldProjectorBlockEntity {
|
||||
} 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);
|
||||
((ServerWorld) getWorld()).spawnParticles(ParticleTypes.SMOKE, vec.getX(), vec.getY(), vec.getZ(), 1, 0.31f, 0.31f, 0.31f, 0f);
|
||||
|
||||
progress++;
|
||||
}
|
||||
|
||||
markDirty();
|
||||
}
|
||||
} else if (progress != 0) {
|
||||
progress = 0;
|
||||
markDirty();
|
||||
|
@ -6,13 +6,18 @@ import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.mob.CreeperEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
|
||||
public class IndustrialLaserBlock extends AbstractFieldBlock {
|
||||
public IndustrialLaserBlock() {
|
||||
@ -29,8 +34,18 @@ public class IndustrialLaserBlock extends AbstractFieldBlock {
|
||||
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
||||
super.onEntityCollision(state, world, pos, entity);
|
||||
|
||||
if (entity instanceof LivingEntity) {
|
||||
if (entity instanceof CreeperEntity) {
|
||||
((CreeperEntity) entity).setIgnited();
|
||||
} else if (entity instanceof LivingEntity) {
|
||||
entity.damage(DamageSource.IN_FIRE, HardcodedConfig.INDUSTRIAL_LASER_BEAM_DAMAGE);
|
||||
} else if (entity instanceof ItemEntity) {
|
||||
ItemStack stack = ((ItemEntity) entity).getStack();
|
||||
if (stack.getItem() == Items.GUNPOWDER) {
|
||||
entity.remove();
|
||||
for (int i = 0; i < stack.getCount(); i++) {
|
||||
world.createExplosion(entity, entity.getX(), entity.getY(), entity.getZ(), 1.5f, Explosion.DestructionType.NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,15 @@
|
||||
package com.thebrokenrail.energonrelics.mixin;
|
||||
|
||||
import com.thebrokenrail.energonrelics.block.forcefield.util.AbstractFieldBlock;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTicker;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(World.class)
|
||||
@ -19,4 +23,11 @@ public abstract class MixinWorld {
|
||||
EnergyTicker.tick((World) (Object) this);
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;syncWorldEvent(ILnet/minecraft/util/math/BlockPos;I)V"), method = "breakBlock")
|
||||
public void breakBlock(World world, int eventId, BlockPos pos, int data) {
|
||||
if (!(Block.getStateFromRawId(data).getBlock() instanceof AbstractFieldBlock)) {
|
||||
world.syncWorldEvent(eventId, pos, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user