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
Raw Normal View History

2020-07-28 20:46:34 +00:00
package com.thebrokenrail.energonrelics.block.forcefield.laser;
2020-07-28 20:38:21 +00:00
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.forcefield.util.AbstractFieldBlock;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
2020-08-20 00:19:27 +00:00
import net.minecraft.block.AbstractFireBlock;
2020-07-28 20:38:21 +00:00
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.entity.Entity;
2020-07-28 21:45:42 +00:00
import net.minecraft.entity.ItemEntity;
2020-07-28 20:38:21 +00:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
2020-07-28 21:45:42 +00:00
import net.minecraft.entity.mob.CreeperEntity;
2020-08-20 00:19:27 +00:00
import net.minecraft.entity.player.PlayerEntity;
2020-08-20 19:24:52 +00:00
import net.minecraft.entity.projectile.SmallFireballEntity;
2020-07-28 21:45:42 +00:00
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
2020-07-28 20:38:21 +00:00
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;
2020-07-28 21:45:42 +00:00
import net.minecraft.world.explosion.Explosion;
2020-07-28 20:38:21 +00:00
public class IndustrialLaserBlock extends AbstractFieldBlock {
public IndustrialLaserBlock() {
super(false);
}
@Override
protected BlockState getProjectorBlockState() {
return EnergonRelics.INDUSTRIAL_LASER_PROJECTOR_BLOCK.getDefaultState();
}
2020-07-28 22:40:35 +00:00
private static class IndustrialLaserDamageSource extends DamageSource {
protected IndustrialLaserDamageSource() {
super(EnergonRelics.NAMESPACE + ".industrial_laser");
setBypassesArmor();
setFire();
}
}
private static final DamageSource DAMAGE_SOURCE = new IndustrialLaserDamageSource();
2020-07-28 20:38:21 +00:00
@SuppressWarnings("deprecation")
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
super.onEntityCollision(state, world, pos, entity);
2020-07-28 21:45:42 +00:00
if (entity instanceof CreeperEntity) {
((CreeperEntity) entity).ignite();
2020-07-28 21:45:42 +00:00
} else if (entity instanceof LivingEntity) {
2020-08-20 00:19:27 +00:00
if (!entity.isFireImmune()) {
2020-08-20 19:24:52 +00:00
entity.setOnFireFor(8);
2020-08-20 00:19:27 +00:00
entity.damage(DAMAGE_SOURCE, HardcodedConfig.INDUSTRIAL_LASER_BEAM_DAMAGE);
}
2020-07-28 21:45:42 +00:00
} 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);
}
}
2020-07-28 20:38:21 +00:00
}
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.empty();
}
}