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/util/BeamBlock.java

48 lines
1.9 KiB
Java

package com.thebrokenrail.energonrelics.block.forcefield.util;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.forcefield.beam.TractorBeamProjectorBlock;
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.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class BeamBlock extends AbstractFieldBlock {
private final boolean isRepulsor;
public BeamBlock(boolean isRepulsor) {
super(false);
this.isRepulsor = isRepulsor;
}
@Override
protected BlockState getProjectorBlockState() {
return EnergonRelics.TRACTOR_BEAM_PROJECTOR_BLOCK.getDefaultState().with(TractorBeamProjectorBlock.IS_REPULSOR, isRepulsor);
}
@SuppressWarnings("deprecation")
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
super.onEntityCollision(state, world, pos, entity);
if (!(entity instanceof PlayerEntity) || !((PlayerEntity) entity).abilities.flying) {
entity.slowMovement(state, new Vec3d(HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER, HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER, HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER));
Direction facing = state.get(FACING);
if (!isRepulsor) {
facing = facing.getOpposite();
}
Vec3d pullForce = Vec3d.of(facing.getVector()).multiply(HardcodedConfig.TRACTOR_BEAM_PULL_FORCE);
entity.addVelocity(pullForce.getX(), pullForce.getY(), pullForce.getZ());
}
}
}