Updated block rotation to be generic

This commit is contained in:
LemADEC 2016-05-19 01:48:19 -04:00
parent 4fb5789d24
commit 6d8666b8a4
2 changed files with 55 additions and 47 deletions

View file

@ -3,12 +3,17 @@ package cr0s.warpdrive.block;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBlockUpdateDetector;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class BlockAbstractContainer extends BlockContainer {
protected boolean isRotating = false;
protected BlockAbstractContainer(Material material) {
super(material);
setHardness(5.0F);
@ -26,6 +31,48 @@ public abstract class BlockAbstractContainer extends BlockContainer {
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemstack) {
if (isRotating) {
if (entityLiving != null) {
int metadata;
if (entityLiving.rotationPitch > 65) {
metadata = 1;
} else if (entityLiving.rotationPitch < -65) {
metadata = 0;
} else {
int direction = Math.round(entityLiving.rotationYaw / 90.0F) & 3;
switch (direction) {
case 0:
metadata = 2;
break;
case 1:
metadata = 5;
break;
case 2:
metadata = 3;
break;
case 3:
metadata = 4;
break;
default:
metadata = 2;
break;
}
}
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
}
} else {
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemstack);
}
}
@Override
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
world.setBlockMetadataWithNotify(x, y, z, axis.ordinal(), 3);
return true;
}
// FIXME untested
/*
@Override

View file

@ -2,15 +2,13 @@ package cr0s.warpdrive.block.detection;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
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.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.block.BlockAbstractContainer;
import cr0s.warpdrive.data.CameraRegistryItem;
@ -22,9 +20,16 @@ public class BlockMonitor extends BlockAbstractContainer {
public BlockMonitor() {
super(Material.iron);
isRotating = true;
setBlockName("warpdrive.detection.Monitor");
}
@Override
public void registerBlockIcons(IIconRegister iconRegister) {
iconFront = iconRegister.registerIcon("warpdrive:detection/monitorFront");
iconSide = iconRegister.registerIcon("warpdrive:detection/monitorSide");
}
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
int metadata = world.getBlockMetadata(x, y, z);
@ -36,50 +41,6 @@ public class BlockMonitor extends BlockAbstractContainer {
return side == 3 ? iconFront : iconSide;
}
@Override
public void registerBlockIcons(IIconRegister iconRegister) {
iconFront = iconRegister.registerIcon("warpdrive:detection/monitorFront");
iconSide = iconRegister.registerIcon("warpdrive:detection/monitorSide");
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemstack) {
int metadata;
if (entityLiving != null) {
if (entityLiving.rotationPitch > 65) {
metadata = 1;
} else if (entityLiving.rotationPitch < -65) {
metadata = 0;
} else {
int direction = Math.round(entityLiving.rotationYaw / 90.0F) & 3;
switch (direction) {
case 0:
metadata = 2;
break;
case 1:
metadata = 5;
break;
case 2:
metadata = 3;
break;
case 3:
metadata = 4;
break;
default:
metadata = 2;
break;
}
}
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
}
}
@Override
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
world.setBlockMetadataWithNotify(x, y, z, axis.ordinal(), 3);
return true;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
// Monitor is only reacting client side