Skip to content

Commit

Permalink
Drawbridge behavior reverted and solidified like pistons, all drawbri…
Browse files Browse the repository at this point in the history
…dges store inventory
  • Loading branch information
mDiyo committed Jan 2, 2014
1 parent c178abd commit 995565c
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 62 deletions.
156 changes: 114 additions & 42 deletions src/tmechworks/blocks/RedstoneMachine.java
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
Expand All @@ -18,7 +17,7 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import tmechworks.lib.blocks.InventoryBlock;
import tconstruct.library.blocks.IDrawbridgeLogicBase;
import tconstruct.library.util.IActiveLogic;
import tconstruct.library.util.IFacingLogic;
import tmechworks.TMechworks;
Expand All @@ -27,6 +26,8 @@
import tmechworks.blocks.logic.FirestarterLogic;
import tmechworks.client.block.MachineRender;
import tmechworks.lib.TMechworksRegistry;
import tmechworks.lib.blocks.InventoryBlock;
import tmechworks.lib.blocks.InventoryLogic;
import tmechworks.lib.util.CoordTuple;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -254,8 +255,8 @@ public int getTextureIndex (int side)
{
return getTextureIndex(side, false);
}
public int getTextureIndex(int side, boolean alt)

public int getTextureIndex (int side, boolean alt)
{
if (side == 0)
return 2;
Expand Down Expand Up @@ -292,29 +293,42 @@ public void onNeighborBlockChange (World world, int x, int y, int z, int neighbo
IActiveLogic logic = (IActiveLogic) world.getBlockTileEntity(x, y, z);
IFacingLogic facing = (IFacingLogic) logic;
int direction = facing.getRenderDirection();
int maxStrength = 0, tmpStrength = 0;
boolean active = false;
CoordTuple coord;

for (int i = 0; i < 6; i++)
{
if (direction == i)
continue;

coord = directions.get(i);
tmpStrength = world.getIndirectPowerLevelTo(x + coord.x, y + coord.y, z + coord.z, (i == 2 || i == 3) ? i : i^1);
if (tmpStrength > maxStrength)
CoordTuple coord = directions.get(i);
if (this.getIndirectPowerLevelTo(world, x + coord.x, y + coord.y, z + coord.z, i) > 0 || activeRedstone(world, coord.x, y + coord.y, z + coord.z))
{
maxStrength = tmpStrength;
active = true;
break;
}
}
if (maxStrength > 0)
logic.setActive(active);
}

public int getIndirectPowerLevelTo (World world, int x, int y, int z, int side)
{
if (world.isBlockNormalCube(x, y, z))
{
active = true;
return world.getBlockPowerInput(x, y, z);
}
else
{
int i1 = world.getBlockId(x, y, z);
return i1 == 0 ? 0 : Block.blocksList[i1].isProvidingWeakPower(world, x, y, z, side);
}
logic.setActive(active);
if (logic instanceof DrawbridgeLogic)
((DrawbridgeLogic) logic).setMaximumExtension((byte)maxStrength);
}

boolean activeRedstone (World world, int x, int y, int z)
{
Block wire = Block.blocksList[world.getBlockId(x, y, z)];
if (wire != null && wire.blockID == Block.redstoneWire.blockID)
return world.getBlockMetadata(x, y, z) > 0;

return false;
}

/* Keep inventory */
Expand All @@ -323,23 +337,44 @@ public boolean removeBlockByPlayer (World world, EntityPlayer player, int x, int
{
player.addExhaustion(0.025F);
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0)
if (meta < 4 && meta != 1)
{
ItemStack stack = new ItemStack(this.blockID, 1, meta);
DrawbridgeLogic logic = (DrawbridgeLogic) world.getBlockTileEntity(x, y, z);
InventoryLogic logic = (InventoryLogic) world.getBlockTileEntity(x, y, z);
NBTTagCompound tag = new NBTTagCompound();
ItemStack camo = null;

boolean hasTag = false;
ItemStack contents = logic.getStackInSlot(0);
if (contents != null)
if (meta == 0 || meta == 3)
{
NBTTagCompound contentTag = new NBTTagCompound();
contents.writeToNBT(contentTag);
tag.setCompoundTag("Contents", contentTag);
hasTag = true;
ItemStack contents = logic.getStackInSlot(0);
if (contents != null)
{
NBTTagCompound contentTag = new NBTTagCompound();
contents.writeToNBT(contentTag);
tag.setCompoundTag("Contents", contentTag);
hasTag = true;
}

camo = logic.getStackInSlot(1);
}
else if (meta == 2)
{
AdvancedDrawbridgeLogic advDrawbridge = (AdvancedDrawbridgeLogic) logic;
camo = advDrawbridge.camoInventory.getCamoStack();
for (int i = 1; i <= 16; i++)
{
ItemStack slot = logic.getStackInSlot(i-1);
if (slot != null)
{
NBTTagCompound contentTag = new NBTTagCompound();
slot.writeToNBT(contentTag);
tag.setCompoundTag("Slot" + i, contentTag);
hasTag = true;
}
}
}

ItemStack camo = logic.getStackInSlot(1);
if (camo != null)
{
NBTTagCompound camoTag = new NBTTagCompound();
Expand All @@ -348,9 +383,10 @@ public boolean removeBlockByPlayer (World world, EntityPlayer player, int x, int
hasTag = true;
}

if (logic.getPlacementDirection() != 4)
IDrawbridgeLogicBase drawbridge = (IDrawbridgeLogicBase) logic;
if (drawbridge.getPlacementDirection() != 4)
{
tag.setByte("Placement", logic.getPlacementDirection());
tag.setByte("Placement", drawbridge.getPlacementDirection());
hasTag = true;
}
if (hasTag == true)
Expand Down Expand Up @@ -389,28 +425,64 @@ public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase
super.onBlockPlacedBy(world, x, y, z, living, stack);
if (stack.hasTagCompound())
{
DrawbridgeLogic logic = (DrawbridgeLogic) world.getBlockTileEntity(x, y, z);
NBTTagCompound contentTag = stack.getTagCompound().getCompoundTag("Contents");
if (contentTag != null)
int meta = stack.getItemDamage();
if (meta == 0 || meta == 3)
{
ItemStack contents = ItemStack.loadItemStackFromNBT(contentTag);
logic.setInventorySlotContents(0, contents);
}
DrawbridgeLogic logic = (DrawbridgeLogic) world.getBlockTileEntity(x, y, z);
NBTTagCompound contentTag = stack.getTagCompound().getCompoundTag("Contents");
if (contentTag != null)
{
ItemStack contents = ItemStack.loadItemStackFromNBT(contentTag);
logic.setInventorySlotContents(0, contents);
}

NBTTagCompound camoTag = stack.getTagCompound().getCompoundTag("Camoflauge");
if (camoTag != null)
{
ItemStack camoflauge = ItemStack.loadItemStackFromNBT(camoTag);
logic.setInventorySlotContents(1, camoflauge);
}
NBTTagCompound camoTag = stack.getTagCompound().getCompoundTag("Camoflauge");
if (camoTag != null)
{
ItemStack camoflauge = ItemStack.loadItemStackFromNBT(camoTag);
logic.setInventorySlotContents(1, camoflauge);
}

if (stack.getTagCompound().hasKey("Placement"))
if (stack.getTagCompound().hasKey("Placement"))
{
logic.setPlacementDirection(stack.getTagCompound().getByte("Placement"));
}
}
else if (meta == 2)
{
logic.setPlacementDirection(stack.getTagCompound().getByte("Placement"));
AdvancedDrawbridgeLogic logic = (AdvancedDrawbridgeLogic) world.getBlockTileEntity(x, y, z);
for (int i = 1; i <= 16; i++)
{
NBTTagCompound contentTag = stack.getTagCompound().getCompoundTag("Slot"+i);
if (contentTag != null)
{
ItemStack contents = ItemStack.loadItemStackFromNBT(contentTag);
logic.setInventorySlotContents(i-1, contents);
}
}

NBTTagCompound camoTag = stack.getTagCompound().getCompoundTag("Camoflauge");
if (camoTag != null)
{
ItemStack camoflauge = ItemStack.loadItemStackFromNBT(camoTag);
logic.camoInventory.setInventorySlotContents(0, camoflauge);
}

if (stack.getTagCompound().hasKey("Placement"))
{
logic.setPlacementDirection(stack.getTagCompound().getByte("Placement"));
}
}
}
}

/* Redstone connections */

public boolean canConnectRedstone (IBlockAccess world, int x, int y, int z, int side)
{
return false;
}

static ArrayList<CoordTuple> directions = new ArrayList<CoordTuple>(6);

static
Expand All @@ -419,7 +491,7 @@ public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase
directions.add(new CoordTuple(0, 1, 0));
directions.add(new CoordTuple(0, 0, -1));
directions.add(new CoordTuple(0, 0, 1));
directions.add(new CoordTuple(1, 0, 0));
directions.add(new CoordTuple(-1, 0, 0));
directions.add(new CoordTuple(1, 0, 0));
}
}
2 changes: 1 addition & 1 deletion src/tmechworks/blocks/logic/DrawbridgeLogic.java
Expand Up @@ -28,7 +28,7 @@ public class DrawbridgeLogic extends InventoryLogic implements IFacingLogic, IAc
boolean working;
int ticks;
byte extension;
byte maxExtension = 15;
byte maxExtension = 15; //Absolute maximum
byte direction;
byte placementDirection = 4;
FakePlayerLogic fakePlayer;
Expand Down
64 changes: 45 additions & 19 deletions src/tmechworks/items/blocks/RedstoneMachineItem.java
Expand Up @@ -33,32 +33,58 @@ public String getUnlocalizedName (ItemStack itemstack)
@Override
public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4)
{
if (stack.hasTagCompound() && stack.getItemDamage() == 0)
int meta = stack.getItemDamage();
if (stack.hasTagCompound())
{
NBTTagCompound contentTags = stack.getTagCompound().getCompoundTag("Contents");
if (contentTags != null)
if (meta != 1)
{
ItemStack contents = ItemStack.loadItemStackFromNBT(contentTags);
if (contents != null)
if (meta == 0 || meta == 3)
{
list.add("Inventory: " + contents.getDisplayName());
list.add("Amount: " + contents.stackSize);
NBTTagCompound contentTags = stack.getTagCompound().getCompoundTag("Contents");
if (contentTags != null)
{
ItemStack contents = ItemStack.loadItemStackFromNBT(contentTags);
if (contents != null)
{
list.add("Inventory: \u00a7f" + contents.getDisplayName());
list.add("Amount: \u00a7f" + contents.stackSize);
}
}
}
else if (meta == 2)
{
for (int i = 1; i <= 16; i++)
{
NBTTagCompound contentTag = stack.getTagCompound().getCompoundTag("Slot" + i);
ItemStack contents = ItemStack.loadItemStackFromNBT(contentTag);
if (contents != null)
{
list.add("Slot " + i + ": \u00a7f" + contents.getDisplayName());
}
}
}
}
NBTTagCompound camoTag = stack.getTagCompound().getCompoundTag("Camoflauge");
if (camoTag != null)
{
ItemStack camo = ItemStack.loadItemStackFromNBT(camoTag);
if (camo != null)
list.add("Camoflauge: " + camo.getDisplayName());
}

if (stack.getTagCompound().hasKey("Placement"))
{
String string = getDirectionString(stack.getTagCompound().getByte("Placement"));
list.add("Placement Direction: " + string);
NBTTagCompound camoTag = stack.getTagCompound().getCompoundTag("Camoflauge");
if (camoTag != null)
{
ItemStack camo = ItemStack.loadItemStackFromNBT(camoTag);
if (camo != null)
{
list.add("\u00a72Camoflauge: \u00a7f" + camo.getDisplayName());
}
}

if (stack.getTagCompound().hasKey("Placement"))
{
String string = getDirectionString(stack.getTagCompound().getByte("Placement"));
list.add("Placement Direction: " + string);
}
}
}
else if (meta != 1)
{
list.add("Stores its inventory when harvested");
}
}

String getDirectionString (byte key)
Expand Down

0 comments on commit 995565c

Please sign in to comment.