Custom ItemBlock for Contractor

This commit is contained in:
Aidan Brady 2013-08-03 13:41:37 -04:00
parent 5262a37826
commit 6c809e1555
4 changed files with 69 additions and 5 deletions

View file

@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.ShapedOreRecipe;
import resonantinduction.contractor.BlockEMContractor;
import resonantinduction.contractor.ItemBlockContractor;
import resonantinduction.contractor.TileEntityEMContractor;
import resonantinduction.entangler.ItemQuantumEntangler;
import resonantinduction.tesla.BlockTesla;
@ -125,7 +126,7 @@ public class ResonantInduction
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
blockEMContractor = new BlockEMContractor(getNextBlockID());
GameRegistry.registerBlock(blockEMContractor, blockEMContractor.getUnlocalizedName());
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
CONFIGURATION.save();

View file

@ -2,9 +2,12 @@ package resonantinduction.contractor;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
@ -28,6 +31,36 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
return BlockRenderingHandler.INSTANCE.getRenderId();
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack)
{
TileEntityEMContractor tileEntity = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
int side = MathHelper.floor_double((double)(entityliving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int height = Math.round(entityliving.rotationPitch);
int change = 1;
if(height >= 65)
{
change = 1;
}
else if(height <= -65)
{
change = 0;
}
else {
switch(side)
{
case 0: change = 2; break;
case 1: change = 5; break;
case 2: change = 3; break;
case 3: change = 4; break;
}
}
tileEntity.setFacing(ForgeDirection.getOrientation(change));
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
@ -43,6 +76,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
if(tileEntity instanceof IInventory)
{
tileContractor.setFacing(side.getOpposite());
return;
}
}
}
@ -78,6 +112,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
if(tileEntity instanceof IInventory)
{
tileContractor.setFacing(side.getOpposite());
return;
}
}
}

View file

@ -0,0 +1,27 @@
package resonantinduction.contractor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItemBlockContractor extends ItemBlock
{
public ItemBlockContractor(int id)
{
super(id);
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
if(place)
{
TileEntityEMContractor tileContractor = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
}
return place;
}
}

View file

@ -22,6 +22,7 @@ public class RenderEMContractor extends TileEntitySpecialRenderer
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
switch(((TileEntityEMContractor)t).getFacing())
{
@ -32,13 +33,13 @@ public class RenderEMContractor extends TileEntitySpecialRenderer
case UP:
break;
case NORTH:
GL11.glTranslatef(-1, 1, 0);
GL11.glRotatef(-90, 0, 0, 1);
break;
case SOUTH:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(90, 0, 0, 1);
break;
case SOUTH:
GL11.glTranslatef(-1, 1, 0);
GL11.glRotatef(-90, 0, 0, 1);
break;
case WEST:
GL11.glTranslatef(0, 1, 1);
GL11.glRotatef(-90, 1, 0, 0);