From 6fcb8f675d7585472bb66e656972b0ad6b05373d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 28 Jul 2020 17:45:42 -0400 Subject: [PATCH] Improve --- .../forcefield/FieldProjectorBlockEntity.java | 6 +++ .../laser/IndustrialLaserBlockEntity.java | 37 +++++++++++++------ .../laser/IndustrialLaserBlock.java | 17 ++++++++- .../energonrelics/mixin/MixinWorld.java | 11 ++++++ 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/FieldProjectorBlockEntity.java b/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/FieldProjectorBlockEntity.java index 7b02ec2..cbca948 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/FieldProjectorBlockEntity.java +++ b/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/FieldProjectorBlockEntity.java @@ -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); + } } } } diff --git a/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/laser/IndustrialLaserBlockEntity.java b/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/laser/IndustrialLaserBlockEntity.java index 0496dca..549a72c 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/laser/IndustrialLaserBlockEntity.java +++ b/src/main/java/com/thebrokenrail/energonrelics/block/entity/forcefield/laser/IndustrialLaserBlockEntity.java @@ -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,24 +46,33 @@ 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 (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); + if (targetState.getBlock() == Blocks.TNT) { + TntBlock.primeTnt(getWorld(), targetPos); + getWorld().setBlockState(targetPos, Blocks.AIR.getDefaultState()); 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); + 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)); + getWorld().breakBlock(targetPos, false); - progress++; + progress = 0; + } else { + Vec3d vec = Vec3d.ofCenter(targetPos); + + ((ServerWorld) getWorld()).spawnParticles(ParticleTypes.SMOKE, vec.getX(), vec.getY(), vec.getZ(), 1, 0.31f, 0.31f, 0.31f, 0f); + + progress++; + } + + markDirty(); } - - markDirty(); } else if (progress != 0) { progress = 0; markDirty(); diff --git a/src/main/java/com/thebrokenrail/energonrelics/block/forcefield/laser/IndustrialLaserBlock.java b/src/main/java/com/thebrokenrail/energonrelics/block/forcefield/laser/IndustrialLaserBlock.java index a5a9d5a..325a29b 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/block/forcefield/laser/IndustrialLaserBlock.java +++ b/src/main/java/com/thebrokenrail/energonrelics/block/forcefield/laser/IndustrialLaserBlock.java @@ -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); + } + } } } diff --git a/src/main/java/com/thebrokenrail/energonrelics/mixin/MixinWorld.java b/src/main/java/com/thebrokenrail/energonrelics/mixin/MixinWorld.java index b365e39..91a1ccf 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/mixin/MixinWorld.java +++ b/src/main/java/com/thebrokenrail/energonrelics/mixin/MixinWorld.java @@ -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); + } + } }