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

44 lines
1.8 KiB
Java
Raw Normal View History

2020-07-28 03:10:16 +00:00
package com.thebrokenrail.energonrelics.block.forcefield.util;
import com.thebrokenrail.energonrelics.EnergonRelics;
2020-07-28 20:46:34 +00:00
import com.thebrokenrail.energonrelics.block.forcefield.beam.TractorBeamProjectorBlock;
2020-07-28 15:53:33 +00:00
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
2020-07-28 03:10:16 +00:00
import net.minecraft.block.BlockState;
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.world.World;
public class BeamBlock extends AbstractFieldBlock {
private final boolean isRepulsor;
public BeamBlock(boolean isRepulsor) {
super(false);
this.isRepulsor = isRepulsor;
}
@Override
protected BlockState getProjectorBlockState() {
2020-08-20 23:03:47 +00:00
return EnergonRelics.Blocks.TRACTOR_BEAM_PROJECTOR.getDefaultState().with(TractorBeamProjectorBlock.IS_REPULSOR, isRepulsor);
2020-07-28 03:10:16 +00:00
}
@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) {
2020-07-28 15:53:33 +00:00
entity.slowMovement(state, new Vec3d(HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER, HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER, HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER));
2020-07-28 03:10:16 +00:00
Direction facing = state.get(FACING);
if (!isRepulsor) {
facing = facing.getOpposite();
}
2020-07-28 15:53:33 +00:00
Vec3d pullForce = Vec3d.of(facing.getVector()).multiply(HardcodedConfig.TRACTOR_BEAM_PULL_FORCE);
2020-07-28 03:10:16 +00:00
entity.addVelocity(pullForce.getX(), pullForce.getY(), pullForce.getZ());
}
}
}