This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/block/forcefield/laser/IndustrialLaserBlock.java

74 lines
2.8 KiB
Java

package com.thebrokenrail.energonrelics.block.forcefield.laser;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.forcefield.util.AbstractFieldBlock;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import net.minecraft.block.AbstractFireBlock;
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.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.SmallFireballEntity;
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() {
super(false);
}
@Override
protected BlockState getProjectorBlockState() {
return EnergonRelics.INDUSTRIAL_LASER_PROJECTOR_BLOCK.getDefaultState();
}
private static class IndustrialLaserDamageSource extends DamageSource {
protected IndustrialLaserDamageSource() {
super(EnergonRelics.NAMESPACE + ".industrial_laser");
setBypassesArmor();
setFire();
}
}
private static final DamageSource DAMAGE_SOURCE = new IndustrialLaserDamageSource();
@SuppressWarnings("deprecation")
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
super.onEntityCollision(state, world, pos, entity);
if (entity instanceof CreeperEntity) {
((CreeperEntity) entity).ignite();
} else if (entity instanceof LivingEntity) {
if (!entity.isFireImmune()) {
entity.setOnFireFor(8);
entity.damage(DAMAGE_SOURCE, 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);
}
}
}
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.empty();
}
}