mffs/src/main/java/mffs/block/BlockForceManipulator.java

92 lines
2.8 KiB
Java
Raw Normal View History

2022-10-28 16:20:12 +02:00
package mffs.block;
import mffs.base.BlockMachine;
import mffs.tileentity.TileEntityForceManipulator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockForceManipulator extends BlockMachine {
public BlockForceManipulator() {
super("manipulator");
}
2023-01-08 16:58:21 +01:00
public static int determineOrientation(
final World world,
final int x,
final int y,
final int z,
final EntityPlayer entityPlayer
) {
if (MathHelper.abs((float) ((Entity) entityPlayer).posX - x) < 2.0f
&& MathHelper.abs((float) ((Entity) entityPlayer).posZ - z) < 2.0f) {
final double var5
= ((Entity) entityPlayer).posY + 1.82 - ((Entity) entityPlayer).yOffset;
2022-10-28 16:20:12 +02:00
if (var5 - y > 2.0) {
return 1;
}
if (y - var5 > 0.0) {
return 0;
}
}
final int var6 = MathHelper.floor_double(
2023-01-08 16:58:21 +01:00
((Entity) entityPlayer).rotationYaw * 4.0f / 360.0f + 0.5
)
& 0x3;
2022-10-28 16:20:12 +02:00
return (var6 == 0)
2023-01-08 16:58:21 +01:00
? 2
: ((var6 == 1) ? 5 : ((var6 == 2) ? 3 : ((var6 == 3) ? 4 : 0)));
2022-10-28 16:20:12 +02:00
}
@Override
2023-01-08 16:58:21 +01:00
public void onBlockPlacedBy(
final World world,
final int x,
final int y,
final int z,
final EntityLivingBase par5EntityLiving,
final ItemStack stack
) {
2022-10-28 16:20:12 +02:00
final int metadata = determineOrientation(
2023-01-08 16:58:21 +01:00
world,
x,
y,
z,
(EntityPlayer) par5EntityLiving
); // TODO: ClassCastException?
2022-10-28 16:20:12 +02:00
world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
}
@Override
2023-01-08 16:58:21 +01:00
public boolean onUseWrench(
final World world,
final int x,
final int y,
final int z,
final EntityPlayer par5EntityPlayer,
final int side,
final float hitX,
final float hitY,
final float hitZ
) {
2022-10-28 16:20:12 +02:00
final int mask = 7;
final int rotMeta = world.getBlockMetadata(x, y, z);
final int masked = rotMeta & ~mask;
final ForgeDirection orientation = ForgeDirection.getOrientation(rotMeta & mask);
2023-01-08 16:58:21 +01:00
final ForgeDirection rotated
= orientation.getRotation(ForgeDirection.getOrientation(side));
world.setBlockMetadataWithNotify(x, y, z, (rotated.ordinal() & mask) | masked, 3);
2022-10-28 16:20:12 +02:00
return true;
}
@Override
public TileEntity createNewTileEntity(final World world, int meta) {
return new TileEntityForceManipulator();
}
}