Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dk.adventures.AdvScreen.Blocks;
- import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
- import dk.adventures.AdvScreen.Constants.RenderIDs;
- import dk.adventures.AdvScreen.TileEntity.TileEntityScreen;
- import dk.adventures.AdvScreen.Utils.Logger;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.renderer.RenderBlocks;
- 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.IBlockAccess;
- import net.minecraft.world.World;
- public class BlockScreen extends BlockBaseContainer
- {
- public BlockScreen()
- {
- super("BlockScreen", Material.rock);
- }
- @Override
- public TileEntity createNewTileEntity(World world, int meta)
- {
- return new TileEntityScreen();
- }
- @Override
- public int colorMultiplier(IBlockAccess par1, int x, int y, int z)
- {
- return 0x00ff00; // Integer.parseInt("ffffff", 16);
- }
- @Override
- public boolean isOpaqueCube()
- {
- return false;
- }
- @Override
- public boolean renderAsNormalBlock()
- {
- return false;
- }
- @Override
- public int getRenderType()
- {
- return RenderIDs.Screen;
- }
- @Override
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
- {
- super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack); //not needed Pahimar eh? ;)
- world.setBlockMetadataWithNotify(x, y, z, 1, 2);
- if (world.getTileEntity(x,y,z) instanceof TileEntityScreen)
- {
- int iOrientation = determineOrientation(world, x, y, z, entityLiving);
- ((TileEntityScreen)world.getTileEntity(x,y,z)).Orientation = iOrientation;
- if (!world.isRemote)
- Minecraft.getMinecraft().thePlayer.sendChatMessage(String.format("Orientation: %d", iOrientation));
- }
- }
- public static int determineOrientation(World world, int x, int y, int z, EntityLivingBase entityLiving)
- {
- int iOrientation = 0; //0=north, 1=east, 2=south, 3=west, 4,5,6,7=Up/NESW, 8,9,10,11=Down/NESW
- int iUpDown = 0;
- if (MathHelper.abs((float) entityLiving.posX - (float) x) < 2.0F && MathHelper.abs((float)entityLiving.posZ - (float)z) < 2.0F)
- {
- double d0 = entityLiving.posY + 1.82D - (double)entityLiving.yOffset;
- if (d0 - (double)y > 2.0D)
- {
- iUpDown = 4;
- }
- if ((double)y - d0 > 0.0D)
- {
- iUpDown = 8;
- }
- }
- int l = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- iOrientation = l + iUpDown;
- return iOrientation;
- }
- @Override
- public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
- {
- //setBlockBounds(0.0f, 0.0f, 0.9f, 1.0f, 1.0f, 1.0f);
- int meta = world.getBlockMetadata(x, y, z);
- // if (meta == 0) //hack test to render block correctly in inventory
- // return;
- setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
- TileEntity ent = world.getTileEntity(x,y,z);
- if (ent instanceof TileEntityScreen)
- {
- int iOri = ((TileEntityScreen)ent).Orientation;
- float fDepth = ((TileEntityScreen)ent).Depth;
- switch (iOri)
- {
- case 0:
- setBlockBounds(0.0f, 0.0f, 1.0f-fDepth, 1.0f, 1.0f, 1.0f);
- break;
- default:
- break;
- }
- }
- }
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float faceX, float faceY, float faceZ)
- {
- if (!world.isRemote && player.getHeldItem() == null && !player.isSneaking())
- {
- Logger.Info(String.format("onBlockActivated (%d,%d,%d)", x, y, z));
- //world.setBlockMetadataWithNotify(x, y, z, 1, 3);
- //this.setLightLevel(15);
- TileEntity te = world.getTileEntity(x,y,z);
- if (te instanceof TileEntityScreen)
- {
- TileEntityScreen screen = (TileEntityScreen)te;
- float fDepth = screen.Depth;
- fDepth = fDepth-0.1f < 0.1f ? 1.0f : fDepth-0.1f;
- screen.Depth = fDepth;
- setBlockBoundsBasedOnState(world, x, y, z);
- world.markBlockForUpdate(x, y, z);
- }
- return true;
- }
- else
- return false;
- }
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement