Skip to content

Commit

Permalink
Some more work on "Eye of the Moon"
Browse files Browse the repository at this point in the history
  • Loading branch information
fuj1n committed Oct 6, 2013
1 parent 28f912a commit 51cc7f8
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 115 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions src/tconstruct/blocks/RedstoneMachine.java
Expand Up @@ -66,7 +66,7 @@ public int getLightValue (IBlockAccess world, int x, int y, int z)
@SideOnly(Side.CLIENT)
public int colorMultiplier (IBlockAccess world, int x, int y, int z)
{
if (world.getBlockMetadata(x, y, z) == 0)
if (world.getBlockMetadata(x, y, z) == 0 && world.getBlockMetadata(x, y, z) == 2)
{
TileEntity logic = world.getBlockTileEntity(x, y, z);

Expand All @@ -75,6 +75,11 @@ public int colorMultiplier (IBlockAccess world, int x, int y, int z)
ItemStack stack = ((DrawbridgeLogic) logic).getStackInSlot(1);
if (stack != null && stack.itemID < 4096 && Block.blocksList[stack.itemID] != null && stack.itemID != this.blockID)
return Block.blocksList[stack.itemID].colorMultiplier(world, x, y, z);
}else if (logic != null && logic instanceof AdvancedDrawbridgeLogic)
{
ItemStack stack = ((AdvancedDrawbridgeLogic) logic).camoInventory.getCamoStack();
if (stack != null && stack.itemID < 4096 && Block.blocksList[stack.itemID] != null && stack.itemID != this.blockID)
return Block.blocksList[stack.itemID].colorMultiplier(world, x, y, z);
}
}

Expand Down Expand Up @@ -143,7 +148,7 @@ public void registerIcons (IconRegister iconRegister)
@Override
public Icon getIcon (int side, int meta)
{
if (meta == 0)
if (meta == 0 || meta == 2)
{
if (side == 5)
return icons[5];
Expand Down
50 changes: 26 additions & 24 deletions src/tconstruct/blocks/logic/AdvancedDrawbridgeLogic.java
Expand Up @@ -22,7 +22,7 @@
import tconstruct.library.util.*;
import tconstruct.util.player.FakePlayerLogic;

public class AdvancedDrawbridgeLogic extends ExpandableInventoryLogic implements IFacingLogic, IActiveLogic, IDrawbridgeLogicBase {
public class AdvancedDrawbridgeLogic extends InventoryLogic implements IFacingLogic, IActiveLogic, IDrawbridgeLogicBase {
boolean active;
boolean working;
int ticks;
Expand All @@ -32,10 +32,14 @@ public class AdvancedDrawbridgeLogic extends ExpandableInventoryLogic implements
byte placementDirection = 4;
FakePlayerLogic fakePlayer;

ArrayList<ItemStack> bufferStacks = new ArrayList<ItemStack>();
ItemStack[] bufferStacks = new ItemStack[getSizeInventory()];

public InvCamo camoInventory = new InvCamo();

public AdvancedDrawbridgeLogic() {
super(16);
}

@Override
public void setWorldObj(World par1World) {
this.worldObj = par1World;
Expand Down Expand Up @@ -181,18 +185,18 @@ public byte getPlacementDirection() {
return placementDirection;
}

@Override
public ItemStack getStackInSlot (int slot){
return slot < inventory.length ? inventory[slot] : null;
}

public ItemStack getStackInBufferSlot(int slot) {
return slot < bufferStacks.size() ? bufferStacks.get(slot) : null;
return slot < bufferStacks.length ? bufferStacks[slot] : null;
}

public void setBufferSlotContents(int slot, ItemStack itemstack) {
if (slot < bufferStacks.size()) {
bufferStacks.set(slot, itemstack);
} else if (slot == bufferStacks.size()) {
bufferStacks.add(itemstack);
} else if (slot < getMaxSize()) {
bufferStacks.ensureCapacity(slot);
bufferStacks.set(slot, itemstack);
if (slot < bufferStacks.length) {
bufferStacks[slot] = itemstack;
} else {
return;
}
Expand Down Expand Up @@ -256,9 +260,9 @@ public void updateEntity() {
Block block = Block.blocksList[worldObj.getBlockId(xPos, yPos, zPos)];
if (block == null || block.isAirBlock(worldObj, xPos, yPos, zPos) || block.isBlockReplaceable(worldObj, xPos, yPos, zPos)) {
// tryExtend(worldObj, xPos, yPos, zPos, direction);
int blockToItem = TConstructRegistry.blockToItemMapping[getStackInBufferSlot(extension).itemID];
int blockToItem = getStackInBufferSlot(extension) != null ? TConstructRegistry.blockToItemMapping[getStackInBufferSlot(extension).itemID] : 0;
if (blockToItem == 0) {
if (getStackInSlot(extension).itemID >= 4096 || Block.blocksList[getStackInSlot(extension).itemID] == null)
if (getStackInSlot(extension) == null || getStackInSlot(extension).itemID >= 4096 || Block.blocksList[getStackInSlot(extension).itemID] == null)
return;
Block placeBlock = Block.blocksList[getStackInBufferSlot(extension).itemID];
placeBlockAt(getStackInBufferSlot(extension), fakePlayer, worldObj, xPos, yPos, zPos, direction, 0, 0, 0, getStackInBufferSlot(extension).getItemDamage(), placeBlock);
Expand Down Expand Up @@ -405,7 +409,6 @@ public void readFromNBT(NBTTagCompound tags) {
}

readBufferFromNBT(tags);

readCustomNBT(tags);
}

Expand All @@ -423,26 +426,25 @@ public void writeToNBT(NBTTagCompound tags) {
}

writeBufferToNBT(tags);

writeCustomNBT(tags);
}

public void readBufferFromNBT(NBTTagCompound tags) {
NBTTagList nbttaglist = tags.getTagList("Buffer");
bufferStacks = new ArrayList<ItemStack>();
bufferStacks.ensureCapacity(nbttaglist.tagCount() > getMaxSize() ? getMaxSize() : nbttaglist.tagCount());
bufferStacks = new ItemStack[getSizeInventory()];
// bufferStacks.ensureCapacity(nbttaglist.tagCount() > getSizeInventory() ? getSizeInventory() : nbttaglist.tagCount());
for (int iter = 0; iter < nbttaglist.tagCount(); iter++) {
NBTTagCompound tagList = (NBTTagCompound) nbttaglist.tagAt(iter);
byte slotID = tagList.getByte("Slot");
if (slotID >= 0 && slotID < bufferStacks.size()) {
if (slotID >= 0 && slotID < bufferStacks.length) {
setBufferSlotContents(slotID, ItemStack.loadItemStackFromNBT(tagList));
}
}
}

public void writeBufferToNBT(NBTTagCompound tags) {
NBTTagList nbttaglist = new NBTTagList();
for (int iter = 0; iter < bufferStacks.size(); iter++) {
for (int iter = 0; iter < bufferStacks.length; iter++) {
if (getStackInBufferSlot(iter) != null) {
NBTTagCompound tagList = new NBTTagCompound();
tagList.setByte("Slot", (byte) iter);
Expand Down Expand Up @@ -485,19 +487,19 @@ public boolean hasExtended() {
@Override
public void onInventoryChanged() {
super.onInventoryChanged();
for (int i = 0; i < getMaxSize(); i++) {
for (int i = 0; i < getSizeInventory(); i++) {
if (getStackInSlot(i) != null) {
setBufferSlotContents(i, getStackInSlot(0).copy());
setBufferSlotContents(i, getStackInSlot(i).copy());
getStackInBufferSlot(i).stackSize = 1;
}
}
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

@Override
public int getMaxSize() {
return 16;
}
// @Override
// public int getMaxSize() {
// return 16;
// }

@Override
public int getInventoryStackLimit() {
Expand Down
Expand Up @@ -7,7 +7,7 @@

import net.minecraft.client.gui.GuiButton;

public class SlotButton extends GuiButton {
public class AdvDrawbridgeButton extends GuiButton {
protected static final ResourceLocation buttonTextures = new ResourceLocation("tinker:textures/gui/slotButton.png");

/** Button width in pixels */
Expand All @@ -21,7 +21,16 @@ public class SlotButton extends GuiButton {

/** The y position of this control. */
public int yPosition;


/** The x position of this control when the GUI is expanded. */
public int xPositionExp;

/** The x position of this control when the GUI is expanded. */
public int yPositionExp;

/** Is the GUI expanded. */
public boolean isGuiExpanded = false;

/** The string displayed on this control. */
public String displayString;

Expand All @@ -35,22 +44,24 @@ public class SlotButton extends GuiButton {
public boolean drawButton;
protected boolean field_82253_i;

public SlotButton(int par1, int par2, int par3, String par4Str) {
this(par1, par2, par3, 200, 20, par4Str);
public AdvDrawbridgeButton(int par1, int par2, int par3, int par4, int par5, String par6Str) {
this(par1, par2, par3, par4, par5, 200, 20, par6Str);
}

public SlotButton(int par1, int par2, int par3, int par4, int par5, String par6Str) {
super(par1, par2, par3, par4, par5, par6Str);
public AdvDrawbridgeButton(int par1, int par2, int par3, int par4, int par5, int par6, int par7, String par8Str) {
super(par1, par2, par3, par6, par7, par8Str);
this.width = 200;
this.height = 20;
this.enabled = true;
this.drawButton = true;
this.id = par1;
this.xPosition = par2;
this.yPosition = par3;
this.width = par4;
this.height = par5;
this.displayString = par6Str;
this.xPositionExp = par4;
this.yPositionExp = par5;
this.width = par6;
this.height = par7;
this.displayString = par8Str;
}

/**
Expand All @@ -77,10 +88,14 @@ public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
FontRenderer fontrenderer = par1Minecraft.fontRenderer;
par1Minecraft.getTextureManager().bindTexture(buttonTextures);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.field_82253_i = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;

int xPosition = isGuiExpanded ? this.xPositionExp : this.xPosition;
int yPosition = isGuiExpanded ? this.yPositionExp : this.yPosition;

this.field_82253_i = par2 >= xPosition && par3 >= yPosition && par2 < xPosition + this.width && par3 < yPosition + this.height;
int k = this.getHoverState(this.field_82253_i);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 26, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 26, this.width / 2, this.height);
this.drawTexturedModalRect(xPosition, yPosition, 0, 46 + k * 26, this.width / 2, this.height);
this.drawTexturedModalRect(xPosition + this.width / 2, yPosition, 200 - this.width / 2, 46 + k * 26, this.width / 2, this.height);
this.mouseDragged(par1Minecraft, par2, par3);
int l = 14737632;

Expand All @@ -90,7 +105,7 @@ public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
l = 16777120;
}

this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
this.drawCenteredString(fontrenderer, this.displayString, xPosition + this.width / 2, yPosition + (this.height - 8) / 2, l);
}
}

Expand All @@ -113,7 +128,10 @@ public void mouseReleased(int par1, int par2) {
* MouseListener.mousePressed(MouseEvent e).
*/
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
return this.enabled && this.drawButton && par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
int xPosition = isGuiExpanded ? this.xPositionExp : this.xPosition;
int yPosition = isGuiExpanded ? this.yPositionExp : this.yPosition;

return this.enabled && this.drawButton && par2 >= xPosition && par3 >= yPosition && par2 < xPosition + this.width && par3 < yPosition + this.height;
}

public boolean func_82252_a() {
Expand Down
33 changes: 28 additions & 5 deletions src/tconstruct/client/gui/AdvDrawbridgeGui.java
Expand Up @@ -2,6 +2,7 @@

import cpw.mods.fml.common.network.PacketDispatcher;
import java.io.*;
import java.util.Iterator;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
Expand All @@ -14,7 +15,9 @@
public class AdvDrawbridgeGui extends GuiContainer
{
public AdvancedDrawbridgeLogic logic;


public boolean isGuiExpanded = false;

public AdvDrawbridgeGui(InventoryPlayer inventoryplayer, AdvancedDrawbridgeLogic frypan, World world, int x, int y, int z)
{
super(frypan.getGuiContainer(inventoryplayer, world, x, y, z));
Expand All @@ -23,12 +26,11 @@ public AdvDrawbridgeGui(InventoryPlayer inventoryplayer, AdvancedDrawbridgeLogic

protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
//fontRenderer.drawString(StatCollector.translateToLocal("aggregator.glowstone"), 60, 6, 0x404040);
fontRenderer.drawString("Drawbridge", 8, 6, 0x404040);
fontRenderer.drawString("Advanced Drawbridge", 8, 6, 0x404040);
fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
}

private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/drawbridge.png");
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/drawbridgeAdvanced.png");

protected void drawGuiContainerBackgroundLayer (float f, int i, int j)
{
Expand All @@ -37,6 +39,12 @@ protected void drawGuiContainerBackgroundLayer (float f, int i, int j)
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
if(!isGuiExpanded){
drawTexturedModalRect(cornerX + 34, cornerY + 35, 238, 0, 18, 18);
}else{
drawTexturedModalRect(cornerX - 7, cornerY + 29, 0, 167, 10, 40);
drawTexturedModalRect(cornerX + 173, cornerY + 29, 10, 167, 10, 40);
}
}

public void initGui ()
Expand Down Expand Up @@ -67,12 +75,27 @@ public void initGui ()
button.enabled = false;
this.buttonList.add(button);

this.buttonList.add(new SlotButton(5, this.width / 2 - 13, this.height / 2 - 52, 26, 26, ""));
this.buttonList.add(new AdvDrawbridgeButton(5, this.width / 2 - 13, this.height / 2 - 52, this.width / 2 + 58, this.height / 2 - 79, 26, 26, "Inv"));
}

public void setExpanded(boolean flag){
this.isGuiExpanded = flag;

Iterator<GuiButton> i1 = this.buttonList.iterator();
while(i1.hasNext()){
GuiButton b = i1.next();
if(b instanceof AdvDrawbridgeButton){
((AdvDrawbridgeButton)b).isGuiExpanded = flag;
} else {
b.drawButton = !flag;
}
}
}

protected void actionPerformed (GuiButton button)
{
if(button.id == 5){
setExpanded(!isGuiExpanded);
return;
}

Expand Down

0 comments on commit 51cc7f8

Please sign in to comment.