Skip to content

Commit

Permalink
Fixes, fixes and release!
Browse files Browse the repository at this point in the history
Bug fixes!
  • Loading branch information
RSDuck committed Aug 29, 2015
1 parent 7a555e3 commit 9bf1c21
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -17,7 +17,7 @@ buildscript {

apply plugin: 'forge'

version = "1.4b"
version = "1.4c"
group= "me.kemal.randomp" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "RandomPeripherals"

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/kemal/randomp/RandomPeripherals.java
Expand Up @@ -4,6 +4,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Timer;

import cofh.api.item.IToolHammer;
Expand All @@ -29,6 +30,7 @@
import me.kemal.randomp.te.TileRandomPMachine;
import me.kemal.randomp.te.TileUniversalInterface;
import me.kemal.randomp.util.CCUtils;
import me.kemal.randomp.util.ComputerUIWrapDummy;
import me.kemal.randomp.util.Util;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
Expand Down Expand Up @@ -77,6 +79,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.ITurtleUpgrade;

Expand Down Expand Up @@ -117,6 +120,8 @@ public Item getTabIconItem() {

public static int inventoryTurtleUpgradeID;
public static int dispenserTurtleUpgradeID;

public static int peripheralSearchTimeout;

public static boolean forceVanillaRecipes;

Expand Down Expand Up @@ -244,6 +249,7 @@ private void loadConfig() {
"If you add an block name to this list, it can be used as peripheral and you can read its NBT Data");
forceVanillaRecipes = config.getBoolean("forceVanillaRecipes", config.CATEGORY_GENERAL, false,
"If enabled no items of external mods will be used in crafting recipes");

if (config.hasChanged()) {
config.save();
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/kemal/randomp/client/ClientProxy.java
Expand Up @@ -22,7 +22,6 @@
import me.kemal.randomp.te.TileHologramProjector;

public class ClientProxy extends CommonProxy {
@Override
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void registerIcons(Pre event) {
Expand Down
Expand Up @@ -143,7 +143,6 @@ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b

@Override
public boolean shouldRender3DInInventory(int modelId) {
// TODO Auto-generated method stub
return false;
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/me/kemal/randomp/common/CommonProxy.java
Expand Up @@ -22,8 +22,4 @@ public void registerTileEntities() {
public void registerRenderer() {
}

@SubscribeEvent
public void registerIcons(Pre event) {
}

}
Expand Up @@ -15,8 +15,8 @@
import net.minecraft.tileentity.TileEntity;

public class PeripheralUniversalNBTRead implements IExtendablePeripheral {
Peripheral peripheral;
TileEntity te;
private Peripheral peripheral;
private TileEntity te;

public PeripheralUniversalNBTRead(TileEntity tile) {
peripheral = new Peripheral();
Expand Down Expand Up @@ -49,7 +49,5 @@ public void attachToComputer(IComputerAccess computer) {

@Override
public void detachFromComputer(IComputerAccess computer) {
// TODO Auto-generated method stub

}
}
43 changes: 40 additions & 3 deletions src/main/java/me/kemal/randomp/te/TileHologramProjector.java
Expand Up @@ -17,6 +17,7 @@
import me.kemal.randomp.RandomPeripherals;
import me.kemal.randomp.util.CCType;
import me.kemal.randomp.util.CCUtils;
import me.kemal.randomp.util.ComputerUIWrapDummy;
import me.kemal.randomp.util.FunctionNotFoundException;
import me.kemal.randomp.util.IExtendablePeripheral;
import me.kemal.randomp.util.Peripheral;
Expand Down Expand Up @@ -53,7 +54,6 @@ public class TileHologramProjector extends TileEntity implements IExtendablePeri
boolean dirty;
protected Peripheral peripheral;

@SideOnly(Side.CLIENT)
int displayListID;

boolean graphicsNeedUpdate;
Expand Down Expand Up @@ -86,6 +86,17 @@ public TileHologramProjector() {
new CCType(String.class, "block",
"The internal name of the block to which it should be set. It's the same name you use in commands"), },
new CCType[] { new CCType(Boolean.class, "True if the block was sucsessfull set") }, this);
peripheral.AddMethod("setBlockMeta", "Sets the projected block and it's meta data at the specific coordinates",
new CCType[] { new CCType(Double.class, "x",
"The X-Coordinate of the block, has to be 0 or more and less than 8", 0, 7),
new CCType(Double.class, "y", "The Y-Coordinate of the block, has be 0 or moreand less than 8", 0, 7),
new CCType(Double.class, "z", "The Z-Coordinate of the block, has to be more than 0 and less than 8", 0,
7),
new CCType(String.class, "block",
"The internal name of the block to which it should be set. It's the same name you use in commands"),
new CCType(Double.class, "metadata", "The meta for the block you set", 0, 16)
},
new CCType[] { new CCType(Boolean.class, "True if the block was sucsessfull set") }, this);
peripheral.AddMethod("getBlock", "Returns the id name of the projected block at the specific coordinates",
new CCType[] { new CCType(Double.class, "x",
"The X-Coordinate of the block, you want to get, has to be 0 or more and less than 8", 0, 7),
Expand Down Expand Up @@ -255,6 +266,22 @@ public Object[] callMethod(IComputerAccess computer, ILuaContext context, String
dirty = true;
return new Object[] { true };
}
case "setBlockMeta": {
Block block = Block.getBlockFromName((String) arguments[3]);
int x = ((Number) arguments[0]).intValue();
int y = ((Number) arguments[1]).intValue();
int z = ((Number) arguments[2]).intValue();
if (block == null)
return new Object[] { false };
setBlock(x, y, z, block);

byte meta = ((Number) arguments[4]).byteValue();

setBlockMetaData(x, y, z, meta);

dirty = true;
return new Object[] { true };
}
case "getBlock": {
int x = ((Number) arguments[0]).intValue();
int y = ((Number) arguments[1]).intValue();
Expand Down Expand Up @@ -355,6 +382,11 @@ public Block getBlock(int x, int y, int z) {
return (x < 0 || y < 0 || z < 0 || x >= hologramWidth || y >= hologramHeight || z >= hologramDepth) ? Blocks.air
: Block.getBlockFromName(hologram[((z * hologramWidth) + x) + y * (hologramWidth * hologramHeight)]);
}

public String getBlockName(int x, int y, int z) {
return (x < 0 || y < 0 || z < 0 || x >= hologramWidth || y >= hologramHeight || z >= hologramDepth) ? "minecraft:air"
: hologram[((z * hologramWidth) + x) + y * (hologramWidth * hologramHeight)];
}

@Override
public TileEntity getTileEntity(int x, int y, int z) {
Expand Down Expand Up @@ -412,8 +444,11 @@ public boolean isHologramDirty() {

@Override
public void attachToComputer(IComputerAccess computer) {
if (!attachedComputer.contains(computer))
//RandomPeripherals.logger.info("Computer requests connecting " + (computer instanceof ComputerUIWrapDummy));
if (!attachedComputer.contains(computer)) {
attachedComputer.add(computer);
//RandomPeripherals.logger.info("Sucessfull attached computer");
}
}

@Override
Expand All @@ -423,14 +458,16 @@ public void detachFromComputer(IComputerAccess computer) {

public void onBlockClick(int clickX, int clickY, int clickZ, int side, int button, ItemStack heldItem) {
if (attachedComputer.size() > 0) {
//RandomPeripherals.logger
// .info("currently are " + attachedComputer.size() + " computers attached to the peripheral");
HashMap<String, Object> heldItemCC = CCUtils.stackToMap(heldItem);
if (heldItem != null)
heldItemCC.put("isBlock", Block.getBlockFromItem(heldItem.getItem()) != Blocks.air);

String[] sides = new String[] { "bottom", "top", "north", "south", "west", "east" };
for (int i = 0; i < attachedComputer.size(); i++)
attachedComputer.get(i).queueEvent("hologramTouch", new Object[] { button, clickX, clickY, clickZ,
sides[side], heldItemCC, attachedComputer.get(i).getAttachmentName() });
sides[side], attachedComputer.get(i).getAttachmentName(), heldItemCC });
}
}

Expand Down
41 changes: 32 additions & 9 deletions src/main/java/me/kemal/randomp/te/TileUniversalInterface.java
Expand Up @@ -11,6 +11,7 @@
import me.kemal.randomp.util.CCUtils;
import me.kemal.randomp.util.ComputerUIWrapDummy;
import me.kemal.randomp.util.FunctionNotFoundException;
import me.kemal.randomp.util.Peripheral;
import me.kemal.randomp.util.PeripheralLuaObjectWrap;
import me.kemal.randomp.util.Util;
import net.minecraft.entity.EntityLivingBase;
Expand Down Expand Up @@ -220,9 +221,25 @@ public TileUniversalInterface() {

}

boolean searchForNeightborPeripherals = false;

@Override
public void updateEntity() {
super.updateEntity();

if (!searchForNeightborPeripherals) {
RandomPeripherals.logger.info("Initial Peripheral search started");
for (int i = 0; i < 6; i++) {
ForgeDirection current = ForgeDirection.getOrientation(i);

addNeightborCache(
worldObj.getTileEntity(current.offsetX + xCoord, current.offsetY + yCoord,
current.offsetZ + zCoord),
xCoord + current.offsetX, yCoord + current.offsetY, zCoord + current.offsetZ);
}
searchForNeightborPeripherals = true;
}

// TODO: clean up!
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
storedEnergy.setMaxExtract(getMaxEnergyOutput(dir.getOpposite().ordinal()));
Expand Down Expand Up @@ -751,12 +768,11 @@ public FluidTank getTank() {

@Override
public void attachToComputer(IComputerAccess computer) {
if (!attachedComputer.contains(computer)) {
//RandomPeripherals.logger.info("UniversalInterface_attachToComputer");
if (!attachedComputer.contains(computer) && !(computer instanceof ComputerUIWrapDummy)) {
attachedComputer.add(computer);
for (int i = 0; i < connectedPeripherals.length; i++)
if (connectedPeripherals[i] != null && ((connectedPeripherals[i] instanceof TileUniversalInterface)
? !((TileUniversalInterface) connectedPeripherals[i]).isStillAttachedToComputer(computer)
: true))
if (connectedPeripherals[i] != null)
connectedPeripherals[i].attach(new ComputerUIWrapDummy(computer, dirs[Util.relDirToAbsDir(facing,
ForgeDirection.getOrientation(i).getOpposite().ordinal())]));
}
Expand All @@ -766,9 +782,14 @@ public void attachToComputer(IComputerAccess computer) {
public void detachFromComputer(IComputerAccess computer) {
attachedComputer.remove(computer);
for (int i = 0; i < connectedPeripherals.length; i++)
if (connectedPeripherals[i] != null && ((connectedPeripherals[i] instanceof TileUniversalInterface)
? ((TileUniversalInterface) connectedPeripherals[i]).isStillAttachedToComputer(computer) : true))
connectedPeripherals[i].detach(computer);
if (connectedPeripherals[i] != null)
if (connectedPeripherals[i] instanceof Peripheral) {
Peripheral peripheral = (Peripheral) connectedPeripherals[i];
if (peripheral.getType() == "universalInterface" && peripheral.isAttachedToComputer(computer)) {
connectedPeripherals[i].detach(computer);
}
} else
connectedPeripherals[i].detach(computer);
}

public boolean isStillAttachedToComputer(IComputerAccess computer) {
Expand Down Expand Up @@ -809,8 +830,10 @@ else if (y > yCoord)
if (connectedPeripherals[side] != null)
for (int i = 0; i < attachedComputer.size(); i++) {
try {
connectedPeripherals[side].attach(new ComputerUIWrapDummy(attachedComputer.get(i), dirs[Util
.relDirToAbsDir(facing, ForgeDirection.getOrientation(side).getOpposite().ordinal())]));
if (!(attachedComputer.get(i) instanceof ComputerUIWrapDummy))
connectedPeripherals[side].attach(
new ComputerUIWrapDummy(attachedComputer.get(i), dirs[Util.relDirToAbsDir(facing,
ForgeDirection.getOrientation(side).getOpposite().ordinal())]));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/me/kemal/randomp/util/ComputerUIWrapDummy.java
Expand Up @@ -3,6 +3,7 @@
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.peripheral.IComputerAccess;
import me.kemal.randomp.RandomPeripherals;

public class ComputerUIWrapDummy implements IComputerAccess {
IComputerAccess computer;
Expand Down Expand Up @@ -50,12 +51,32 @@ public void queueEvent(String event, Object[] arguments) {

@Override
public String getAttachmentName() {
return "UIWrapped_" + side;
return computer.getAttachmentName() + "_UIWrapped_" + side;
}

@Override
public boolean equals(Object obj) {
return computer.equals(obj);
if (obj == this)
return true;
if (obj == null)
return false;
if (obj instanceof ComputerUIWrapDummy) {
ComputerUIWrapDummy c = (ComputerUIWrapDummy) obj;

return (computer.getID() == c.getID() || computer == c.computer || computer.equals(c.computer));
}
if (obj instanceof IComputerAccess) {
IComputerAccess c = (IComputerAccess) obj;

return computer.getID() == c.getID() || computer == c || computer.equals(c);
}

return false;
}

@Override
public int hashCode() {
return computer.hashCode();
}

}
14 changes: 12 additions & 2 deletions src/main/java/me/kemal/randomp/util/Peripheral.java
Expand Up @@ -25,6 +25,7 @@ public class Peripheral implements IExtendablePeripheral, IPeripheral {
private HashMap<String, CCType[]> functionReturns;
private HashMap<String, IExtendablePeripheral> peripheralHolders;
private Vector<IExtendablePeripheral> peripheralCallbacks;
private Vector<IComputerAccess> attachedComputers;

public Peripheral() {
functionNames = new Vector<String>();
Expand All @@ -34,6 +35,7 @@ public Peripheral() {
peripheralHolders = new HashMap<String, IExtendablePeripheral>();
peripheralCallbacks = new Vector<IExtendablePeripheral>();
peripheralDescription = "";
attachedComputers = new Vector<IComputerAccess>();

AddMethod("help", "Get Help about an function",
new CCType[] {
Expand Down Expand Up @@ -123,13 +125,17 @@ public Object[] callMethod(IComputerAccess computer, ILuaContext context, int me

@Override
public void attach(IComputerAccess computer) {
for (int i = 0; i < peripheralCallbacks.size(); i++) {
peripheralCallbacks.get(i).attachToComputer(computer);
if (!attachedComputers.contains(computer)) {
attachedComputers.add(computer);
for (int i = 0; i < peripheralCallbacks.size(); i++) {
peripheralCallbacks.get(i).attachToComputer(computer);
}
}
}

@Override
public void detach(IComputerAccess computer) {
attachedComputers.remove(computer);
for (int i = 0; i < peripheralCallbacks.size(); i++) {
peripheralCallbacks.get(i).detachFromComputer(computer);
}
Expand Down Expand Up @@ -182,4 +188,8 @@ public void attachToComputer(IComputerAccess computer) {
@Override
public void detachFromComputer(IComputerAccess computer) {
}

public boolean isAttachedToComputer(IComputerAccess computer) {
return attachedComputers.contains(computer);
}
}

0 comments on commit 9bf1c21

Please sign in to comment.