mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-10-26 14:24:33 +00:00
Framing table multiblock more or less polished off
This commit is contained in:
1 parent
37a304cc70
commit
9865dd0c9c
2 files changed
+142
-16
No files matched your search
@@ -3,20 +3,33 @@ package com.jaquadro.minecraft.storagedrawers.block;
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityFramingTable;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ClientProxy;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModBlocks;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockFramingTable extends BlockContainer
|
||||
{
|
||||
public static final int[][] leftOffset = new int[][] {{0, 0}, {0, 0}, {1, 0}, {-1, 0}, {0, -1}, {0, 1}};
|
||||
public static final int[][] rightOffset = new int[][] {{0, 0}, {0, 0}, {-1, 0}, {1, 0}, {0, 1}, {0, -1}};
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon iconBase;
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -54,29 +67,17 @@ public class BlockFramingTable extends BlockContainer
|
||||
}
|
||||
|
||||
private int getXOff (int meta) {
|
||||
if ((meta & 0x8) == 0)
|
||||
if (isRightBlock(meta))
|
||||
return 0;
|
||||
|
||||
int side = meta & 0x7;
|
||||
if (side == 2)
|
||||
return -1;
|
||||
else if (side == 3)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
return rightOffset[getDirection(meta)][0];
|
||||
}
|
||||
|
||||
private int getZOff (int meta) {
|
||||
if ((meta & 0x8) == 0)
|
||||
if (isRightBlock(meta))
|
||||
return 0;
|
||||
|
||||
int side = meta & 0x7;
|
||||
if (side == 4)
|
||||
return 1;
|
||||
else if (side == 5)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
return rightOffset[getDirection(meta)][1];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,6 +106,100 @@ public class BlockFramingTable extends BlockContainer
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange (World world, int x, int y, int z, Block block) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
int side = getDirection(meta);
|
||||
|
||||
if (isRightBlock(meta)) {
|
||||
if (world.getBlock(x + leftOffset[side][0], y, z + leftOffset[side][1]) != this) {
|
||||
world.setBlockToAir(x, y, z);
|
||||
if (!world.isRemote)
|
||||
dropBlockAsItem(world, x, y, z, 1, 0);
|
||||
}
|
||||
}
|
||||
else if (world.getBlock(x + rightOffset[side][0], y, z + rightOffset[side][1]) != this)
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDropped (int meta, Random random, int fortune) {
|
||||
return isPrimaryBlock(meta) ? Item.getItemFromBlock(ModBlocks.framingTable) : Item.getItemById(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropBlockAsItemWithChance (World world, int x, int y, int z, int meta, float chance, int fortune) {
|
||||
if (isPrimaryBlock(meta))
|
||||
super.dropBlockAsItemWithChance(world, x, y, z, meta, chance, fortune);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMobilityFlag () {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockHarvested (World world, int x, int y, int z, int meta, EntityPlayer player) {
|
||||
if (player.capabilities.isCreativeMode && !isPrimaryBlock(meta)) {
|
||||
int side = getDirection(meta);
|
||||
x += rightOffset[side][0];
|
||||
z += rightOffset[side][1];
|
||||
|
||||
if (world.getBlock(x, y, z) == this)
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock (World world, int x, int y, int z, Block block, int side) {
|
||||
TileEntityFramingTable tile = (TileEntityFramingTable)world.getTileEntity(x, y, z);
|
||||
if (tile != null && isPrimaryBlock(world.getBlockMetadata(x, y, z))) {
|
||||
for (int i = 0, n = tile.getSizeInventory(); i < n; i++) {
|
||||
ItemStack stack = tile.getStackInSlot(i);
|
||||
if (stack == null)
|
||||
continue;
|
||||
|
||||
float fx = random.nextFloat() * .8f + .1f;
|
||||
float fy = random.nextFloat() * .8f + .1f;
|
||||
float fz = random.nextFloat() * .8f + .1f;
|
||||
|
||||
while (stack.stackSize > 0) {
|
||||
int amount = random.nextInt(21) + 10;
|
||||
if (amount > stack.stackSize)
|
||||
amount = stack.stackSize;
|
||||
|
||||
stack.stackSize -= amount;
|
||||
EntityItem entity = new EntityItem(world, x + fx, y + fy, z + fz, new ItemStack(stack.getItem(), amount, stack.getItemDamage()));
|
||||
|
||||
if (stack.hasTagCompound())
|
||||
entity.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
|
||||
|
||||
entity.motionX = random.nextGaussian() * .05f;
|
||||
entity.motionY = random.nextGaussian() * .05f + .2f;
|
||||
entity.motionZ = random.nextGaussian() * .05f;
|
||||
|
||||
world.spawnEntityInWorld(entity);
|
||||
}
|
||||
}
|
||||
|
||||
world.func_147453_f(x, y, z, block);
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, block, side);
|
||||
}
|
||||
|
||||
public static int getDirection (int meta) {
|
||||
return meta & 0x7;
|
||||
}
|
||||
|
||||
public static boolean isRightBlock (int meta) {
|
||||
return (meta & 0x8) == 0;
|
||||
}
|
||||
|
||||
public static boolean isPrimaryBlock (int meta) {
|
||||
return isRightBlock(meta);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconBase () {
|
||||
return iconBase;
|
||||
|
||||
@@ -9,6 +9,7 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class FramingTableRenderer implements ISimpleBlockRenderingHandler
|
||||
{
|
||||
@@ -16,7 +17,37 @@ public class FramingTableRenderer implements ISimpleBlockRenderingHandler
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock (Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
if (!(block instanceof BlockFramingTable))
|
||||
return;
|
||||
|
||||
BlockFramingTable framingTable = (BlockFramingTable)block;
|
||||
|
||||
boolean blendEnabled = GL11.glIsEnabled(GL11.GL_BLEND);
|
||||
if (blendEnabled)
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
|
||||
boolean depthMask = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK);
|
||||
if (!depthMask)
|
||||
GL11.glDepthMask(true);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glRotatef(90, 0, 1, 0);
|
||||
GL11.glTranslatef(.15f, -.5f, -.5f);
|
||||
GL11.glScalef(.65f, .65f, .65f);
|
||||
|
||||
RenderHelper.instance.state.setUVRotation(RenderHelper.YPOS, RenderHelper.instance.state.rotateTransform);
|
||||
|
||||
framingRenderer.renderRight(null, 0, 0, 0, framingTable);
|
||||
framingRenderer.renderLeft(null, -1, 0, 0, framingTable);
|
||||
|
||||
RenderHelper.instance.state.clearUVRotation(RenderHelper.YPOS);
|
||||
|
||||
if (!blendEnabled)
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
if (!depthMask)
|
||||
GL11.glDepthMask(false);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user