mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-25 06:24:24 +00:00
Add basic item buffer. WIP.
This commit is contained in:
1 parent
950140aa15
commit
a1bce90bd6
17 files changed
+388
-23
No files matched your search
@@ -198,6 +198,7 @@ public class ClientProxy extends CommonProxy {
|
||||
super.load();
|
||||
|
||||
//make sure the tooltip stuff is registered
|
||||
@SuppressWarnings("unused")
|
||||
TooltipAddera tta = TooltipAddera.instance;
|
||||
|
||||
// Renderers
|
||||
@@ -211,6 +212,7 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockPowerMonitor), machRen);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockPainter), machRen);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockCrafter), machRen);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockBuffer), machRen);
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(EnderIO.itemBrokenSpawner, new BrokenSpawnerRenderer());
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ import crazypants.enderio.machine.PacketRedstoneMode;
|
||||
import crazypants.enderio.machine.alloy.AlloyRecipeManager;
|
||||
import crazypants.enderio.machine.alloy.BlockAlloySmelter;
|
||||
import crazypants.enderio.machine.attractor.BlockAttractor;
|
||||
import crazypants.enderio.machine.buffer.BlockBuffer;
|
||||
import crazypants.enderio.machine.capbank.BlockCapBank;
|
||||
import crazypants.enderio.machine.crafter.BlockCrafter;
|
||||
import crazypants.enderio.machine.crusher.BlockCrusher;
|
||||
@@ -239,6 +240,7 @@ public class EnderIO {
|
||||
public static BlockSpawnGuard blockSpawnGuard;
|
||||
public static BlockExperienceObelisk blockExperianceOblisk;
|
||||
public static BlockTransceiver blockTransceiver;
|
||||
public static BlockBuffer blockBuffer;
|
||||
|
||||
public static BlockKillerJoe blockKillerJoe;
|
||||
|
||||
@@ -337,6 +339,8 @@ public class EnderIO {
|
||||
blockVacuumChest = BlockVacuumChest.create();
|
||||
|
||||
blockTransceiver = BlockTransceiver.create();
|
||||
|
||||
blockBuffer = BlockBuffer.create();
|
||||
|
||||
blockEnderIo = BlockEnderIO.create();
|
||||
blockTravelPlatform = BlockTravelAnchor.create();
|
||||
|
||||
@@ -50,8 +50,9 @@ public class GuiHandler implements IGuiHandler {
|
||||
public static final int GUI_ID_TRANSCEIVER = 97;
|
||||
public static final int GUI_ID_XP_OBELISK = 98;
|
||||
public static final int GUI_ID_ANVIL = 99;
|
||||
public static final int GUI_ID_BUFFER = 100;
|
||||
|
||||
public static final int GUI_ID_CAP_BANK = 100;
|
||||
public static final int GUI_ID_CAP_BANK = 142; // leave room for more machines
|
||||
|
||||
protected final Map<Integer, IGuiHandler> guiHandlers = new HashMap<Integer, IGuiHandler>();
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public enum ModObject {
|
||||
blockSpawnGuard,
|
||||
blockExperienceObelisk,
|
||||
blockTransceiver,
|
||||
blockBuffer,
|
||||
|
||||
blockPoweredSpawner,
|
||||
itemBrokenSpawner,
|
||||
|
||||
@@ -324,10 +324,15 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
|
||||
BlockCoord loc = getLocation().getLocation(dir);
|
||||
TileEntity te = worldObj.getTileEntity(loc.x, loc.y, loc.z);
|
||||
|
||||
return doPush(dir, te, slotDefinition.minOutputSlot, slotDefinition.maxInputSlot);
|
||||
}
|
||||
|
||||
protected boolean doPush(ForgeDirection dir, TileEntity te, int minSlot, int maxSlot) {
|
||||
if(te == null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
|
||||
for (int i = minSlot; i <= maxSlot; i++) {
|
||||
ItemStack item = inventory[i];
|
||||
if(item != null) {
|
||||
int num = ItemUtil.doInsertItem(te, item, dir.getOpposite());
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -12,11 +13,15 @@ import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import crazypants.enderio.machine.painter.IPaintableTileEntity;
|
||||
import crazypants.enderio.machine.painter.PaintedBlockRenderer;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.render.CubeRenderer;
|
||||
import crazypants.render.CustomCubeRenderer;
|
||||
import crazypants.render.CustomRenderBlocks;
|
||||
import crazypants.render.IRenderFace;
|
||||
import crazypants.render.IconUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.vecmath.Vertex;
|
||||
|
||||
@@ -27,6 +32,8 @@ public class AbstractMachineRenderer implements ISimpleBlockRenderingHandler, II
|
||||
private AbstractMachineEntity curEnt;
|
||||
|
||||
private CustomCubeRenderer ccr = new CustomCubeRenderer();
|
||||
|
||||
private PaintedBlockRenderer paintedRenderer = new PaintedBlockRenderer(this.getRenderId(), null); // passthrough renderer for paintable machines
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
@@ -40,7 +47,12 @@ public class AbstractMachineRenderer implements ISimpleBlockRenderingHandler, II
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
renderInventoryBlock(Block.getBlockFromItem(item.getItem()), item.getItemDamage(), 0, (RenderBlocks)data[0]);
|
||||
Block block;
|
||||
if ((block = PainterUtil.getSourceBlock(item)) != null) {
|
||||
paintedRenderer.renderInventoryBlock(block, PainterUtil.getSourceBlockMetadata(item), 0, (RenderBlocks)data[0]);
|
||||
} else {
|
||||
renderInventoryBlock(Block.getBlockFromItem(item.getItem()), item.getItemDamage(), 0, (RenderBlocks)data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +69,7 @@ public class AbstractMachineRenderer implements ISimpleBlockRenderingHandler, II
|
||||
brightnessPerSide[dir.ordinal()] = Math.max(RenderUtil.getColorMultiplierForFace(dir) + 0.1f, 1f);
|
||||
}
|
||||
CubeRenderer.render(bb, textures, null, brightnessPerSide);
|
||||
Tessellator.instance.draw();
|
||||
Tessellator.instance.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +81,15 @@ public class AbstractMachineRenderer implements ISimpleBlockRenderingHandler, II
|
||||
} else {
|
||||
curEnt = null;
|
||||
}
|
||||
ccr.renderBlock(world, block, x, y, z, overlayRenderer);
|
||||
|
||||
if (te instanceof IPaintableTileEntity && ((IPaintableTileEntity) te).getSourceBlock() != null) {
|
||||
ccr.setOverrideTexture(IconUtil.blankTexture);
|
||||
ccr.renderBlock(world, block, x, y, z, overlayRenderer);
|
||||
ccr.setOverrideTexture(null);
|
||||
paintedRenderer.renderWorldBlock(world, x, y, z, block, modelId, renderer);
|
||||
} else {
|
||||
ccr.renderBlock(world, block, x, y, z, overlayRenderer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -95,7 +115,8 @@ public class AbstractMachineRenderer implements ISimpleBlockRenderingHandler, II
|
||||
IoMode mode = curEnt.getIoMode(face);
|
||||
IIcon tex = ((AbstractMachineBlock)par1Block).getOverlayIconForMode(mode);
|
||||
if(tex != null) {
|
||||
ccr.getCustomRenderBlocks().doDefaultRenderFace(face,par1Block,x,y,z, tex);
|
||||
// dirty z-fighting hax, avert your eyes!
|
||||
ccr.getCustomRenderBlocks().doDefaultRenderFace(face, par1Block, x + (face.offsetX * 0.0001), y + (face.offsetY * 0.0001), z + (face.offsetZ * 0.0001), tex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
package crazypants.enderio.machine.buffer;
|
||||
|
||||
import info.jbcs.minecraft.chisel.api.IFacade;
|
||||
import net.minecraft.block.Block;
|
||||
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.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.MachineRecipeRegistry;
|
||||
import crazypants.enderio.machine.painter.BasicPainterTemplate;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
|
||||
public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFacade {
|
||||
|
||||
public static BlockBuffer create() {
|
||||
BlockBuffer res = new BlockBuffer();
|
||||
res.init();
|
||||
return res;
|
||||
}
|
||||
|
||||
private BlockBuffer() {
|
||||
super(ModObject.blockBuffer, TileBuffer.class);
|
||||
setBlockTextureName("enderio:blockBuffer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_BUFFER, this);
|
||||
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPainter.unlocalisedName, new PainterTemplate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileBuffer) {
|
||||
return new ContainerBuffer(player.inventory, (TileBuffer) te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileBuffer) {
|
||||
return new GuiBuffer(player.inventory, (TileBuffer) te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getGuiId() {
|
||||
return GuiHandler.GUI_ID_BUFFER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMachineFrontIconKey(boolean active) {
|
||||
return this.textureName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackIconKey(boolean active) {
|
||||
return getMachineFrontIconKey(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSideIconKey(boolean active) {
|
||||
return getMachineFrontIconKey(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int blockSide) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileBuffer) {
|
||||
TileBuffer tef = (TileBuffer) te;
|
||||
if(tef.getSourceBlock() != null) {
|
||||
return tef.getSourceBlock().getIcon(blockSide, tef.getSourceBlockMetadata());
|
||||
}
|
||||
}
|
||||
return super.getIcon(world, x, y, z, blockSide);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack par6ItemStack) {
|
||||
if(entity instanceof EntityPlayer) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileBuffer) {
|
||||
TileBuffer ta = (TileBuffer) te;
|
||||
ta.setSourceBlock(PainterUtil.getSourceBlock(par6ItemStack));
|
||||
ta.setSourceBlockMetadata(PainterUtil.getSourceBlockMetadata(par6ItemStack));
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack createItemStackForSourceBlock(Block block, int damage) {
|
||||
ItemStack result = new ItemStack(this, 1, damage);
|
||||
PainterUtil.setSourceBlock(result, block, damage);
|
||||
return result;
|
||||
}
|
||||
|
||||
public final class PainterTemplate extends BasicPainterTemplate {
|
||||
|
||||
public PainterTemplate() {
|
||||
super(BlockBuffer.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultStack[] getCompletedResult(float chance, MachineRecipeInput... inputs) {
|
||||
ItemStack paintSource = MachineRecipeInput.getInputForSlot(1, inputs);
|
||||
if(paintSource == null) {
|
||||
return new ResultStack[0];
|
||||
}
|
||||
return new ResultStack[] { new ResultStack(createItemStackForSourceBlock(Block.getBlockFromItem(paintSource.getItem()), paintSource.getItemDamage())) };
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFacadeMetadata(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (te instanceof TileBuffer) {
|
||||
return ((TileBuffer)te).getSourceBlockMetadata();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getFacade(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (te instanceof TileBuffer) {
|
||||
return ((TileBuffer)te).getSourceBlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package crazypants.enderio.machine.buffer;
|
||||
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import crazypants.enderio.machine.AbstractMachineRenderer;
|
||||
|
||||
public class BlockRendererBuffer extends AbstractMachineRenderer implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package crazypants.enderio.machine.buffer;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.gui.AbstractMachineContainer;
|
||||
|
||||
public class ContainerBuffer extends AbstractMachineContainer {
|
||||
|
||||
public ContainerBuffer(InventoryPlayer playerInv, AbstractMachineEntity te) {
|
||||
super(playerInv, te);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addMachineSlots(InventoryPlayer playerInv) {
|
||||
Point point = new Point(62, 15);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
addSlotToContainer(new Slot(this.tileEntity, i, point.x + ((i % 3) * 18), point.y + ((i / 3) * 18)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package crazypants.enderio.machine.buffer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import crazypants.enderio.machine.gui.GuiMachineBase;
|
||||
import crazypants.render.RenderUtil;
|
||||
|
||||
public class GuiBuffer extends GuiMachineBase {
|
||||
|
||||
public GuiBuffer(InventoryPlayer par1InventoryPlayer, TileBuffer te) {
|
||||
super(te, new ContainerBuffer(par1InventoryPlayer, te));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showRecipeButton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderUtil.bindTexture("enderio:textures/gui/buffer.png");
|
||||
int sx = (width - xSize) / 2;
|
||||
int sy = (height - ySize) / 2;
|
||||
|
||||
drawTexturedModalRect(sx, sy, 0, 0, xSize, ySize);
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package crazypants.enderio.machine.buffer;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.machine.painter.IPaintableTileEntity;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class TileBuffer extends AbstractMachineEntity implements IPaintableTileEntity {
|
||||
|
||||
private Block sourceBlock;
|
||||
private int sourceBlockMetadata;
|
||||
|
||||
public TileBuffer() {
|
||||
super(new SlotDefinition(9, 0, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMachineName() {
|
||||
return ModObject.blockBuffer.unlocalisedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMachineItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return 0; // no tasks
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean processTasks(boolean redstoneCheckPassed) {
|
||||
return false; // no tasks
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack var2, int side) {
|
||||
return super.canInsertItem(slot, var2, side) && getIoMode(ForgeDirection.VALID_DIRECTIONS[side]).canRecieveInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack itemstack, int side) {
|
||||
return super.canExtractItem(slot, itemstack, side) && getIoMode(ForgeDirection.VALID_DIRECTIONS[side]).canOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doPush(ForgeDirection dir) {
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockCoord loc = getLocation().getLocation(dir);
|
||||
TileEntity te = worldObj.getTileEntity(loc.x, loc.y, loc.z);
|
||||
return doPush(dir, te, slotDefinition.minInputSlot, slotDefinition.maxInputSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
PainterUtil.setSourceBlock(nbtRoot, sourceBlock, sourceBlockMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
this.sourceBlock = PainterUtil.getSourceBlock(nbtRoot);
|
||||
this.sourceBlockMetadata = PainterUtil.getSourceBlockMetadata(nbtRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSourceBlockMetadata(int sourceBlockMetadata) {
|
||||
this.sourceBlockMetadata = sourceBlockMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceBlockMetadata() {
|
||||
return sourceBlockMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSourceBlock(Block sourceBlock) {
|
||||
this.sourceBlock = sourceBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getSourceBlock() {
|
||||
return sourceBlock;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.machine.painter;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -23,16 +25,26 @@ public final class PainterUtil {
|
||||
|
||||
public static Block getSourceBlock(ItemStack item) {
|
||||
NBTTagCompound tag = item.getTagCompound();
|
||||
return getSourceBlock(tag);
|
||||
}
|
||||
|
||||
public static Block getSourceBlock(NBTTagCompound tag) {
|
||||
if(tag != null) {
|
||||
String blockId = tag.getString(BlockPainter.KEY_SOURCE_BLOCK_ID);
|
||||
Block res = GameData.blockRegistry.get(blockId);
|
||||
return res;
|
||||
if(!Strings.isNullOrEmpty(blockId)) {
|
||||
Block res = (Block) Block.blockRegistry.getObject(blockId);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getSourceBlockMetadata(ItemStack item) {
|
||||
NBTTagCompound tag = item.getTagCompound();
|
||||
return getSourceBlockMetadata(tag);
|
||||
}
|
||||
|
||||
public static int getSourceBlockMetadata(NBTTagCompound tag) {
|
||||
if(tag != null) {
|
||||
return tag.getInteger(BlockPainter.KEY_SOURCE_BLOCK_META);
|
||||
}
|
||||
@@ -58,6 +70,13 @@ public final class PainterUtil {
|
||||
tag = new NBTTagCompound();
|
||||
item.setTagCompound(tag);
|
||||
}
|
||||
setSourceBlock(item.getTagCompound(), source, meta);
|
||||
}
|
||||
|
||||
public static void setSourceBlock(NBTTagCompound tag, Block source, int meta) {
|
||||
if (tag == null) {
|
||||
return;
|
||||
}
|
||||
String name = Block.blockRegistry.getNameForObject(source);
|
||||
if(name != null && !name.trim().isEmpty()) {
|
||||
tag.setString(BlockPainter.KEY_SOURCE_BLOCK_ID, name);
|
||||
|
||||
@@ -10,7 +10,6 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
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.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
@@ -76,7 +75,7 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
|
||||
super.init();
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TRAVEL_ACCESSABLE, this);
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TRAVEL_AUTH, this);
|
||||
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPainter.unlocalisedName, new PainterTemplate(this));
|
||||
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPainter.unlocalisedName, new PainterTemplate());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -226,8 +225,8 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
public static ItemStack createItemStackForSourceBlock(Block block, int damage) {
|
||||
ItemStack result = new ItemStack(EnderIO.blockTravelPlatform, 1, damage);
|
||||
public ItemStack createItemStackForSourceBlock(Block block, int damage) {
|
||||
ItemStack result = new ItemStack(this, 1, damage);
|
||||
PainterUtil.setSourceBlock(result, block, damage);
|
||||
return result;
|
||||
}
|
||||
@@ -237,10 +236,10 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final class PainterTemplate extends BasicPainterTemplate {
|
||||
public final class PainterTemplate extends BasicPainterTemplate {
|
||||
|
||||
public PainterTemplate(Block ta) {
|
||||
super(ta);
|
||||
public PainterTemplate() {
|
||||
super(BlockTravelAnchor.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -248,8 +247,6 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
|
||||
ItemStack paintSource = MachineRecipeInput.getInputForSlot(1, inputs);
|
||||
if(paintSource == null) {
|
||||
return new ResultStack[0];
|
||||
} else if(paintSource.getItem() == Item.getItemFromBlock(EnderIO.blockTravelPlatform)) {
|
||||
return new ResultStack[] { new ResultStack(new ItemStack(EnderIO.blockTravelPlatform)) };
|
||||
}
|
||||
return new ResultStack[] { new ResultStack(createItemStackForSourceBlock(Block.getBlockFromItem(paintSource.getItem()), paintSource.getItemDamage())) };
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public final class CubeRenderer {
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
|
||||
tex = faceTextures[ForgeDirection.NORTH.ordinal()];
|
||||
tex = getTexSafe(faceTextures, ForgeDirection.NORTH);
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
@@ -233,7 +233,7 @@ public final class CubeRenderer {
|
||||
float cm = brightnessPerSide[ForgeDirection.SOUTH.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.SOUTH.ordinal()];
|
||||
tex = getTexSafe(faceTextures, ForgeDirection.NORTH);
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
@@ -248,7 +248,7 @@ public final class CubeRenderer {
|
||||
float cm = brightnessPerSide[ForgeDirection.UP.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.UP.ordinal()];
|
||||
tex = getTexSafe(faceTextures, ForgeDirection.UP);
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
@@ -263,7 +263,7 @@ public final class CubeRenderer {
|
||||
float cm = brightnessPerSide[ForgeDirection.DOWN.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.DOWN.ordinal()];
|
||||
tex = getTexSafe(faceTextures, ForgeDirection.DOWN);
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
@@ -278,7 +278,7 @@ public final class CubeRenderer {
|
||||
float cm = brightnessPerSide[ForgeDirection.EAST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.EAST.ordinal()];
|
||||
tex = getTexSafe(faceTextures, ForgeDirection.EAST);
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
@@ -293,7 +293,7 @@ public final class CubeRenderer {
|
||||
float cm = brightnessPerSide[ForgeDirection.WEST.ordinal()];
|
||||
tessellator.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
tex = faceTextures[ForgeDirection.WEST.ordinal()];
|
||||
tex = getTexSafe(faceTextures, ForgeDirection.WEST);
|
||||
minU = tex.getMinU();
|
||||
maxU = tex.getMaxU();
|
||||
minV = tex.getMinV();
|
||||
@@ -303,6 +303,11 @@ public final class CubeRenderer {
|
||||
addVecWithUV(verts[7], maxU, minV);
|
||||
addVecWithUV(verts[3], minU, minV);
|
||||
}
|
||||
|
||||
private static IIcon getTexSafe(IIcon[] faceTextures, ForgeDirection dir) {
|
||||
int i = dir.ordinal();
|
||||
return faceTextures[i] == null ? IconUtil.errorTexture : faceTextures[i];
|
||||
}
|
||||
|
||||
public static void setupVertices(BoundingBox bound) {
|
||||
setupVertices(bound, null);
|
||||
|
||||
Reference in new issue
Block a user