Browse Source

MAJOR redstone/internal refactor

pull/3/head
asiekierka 5 years ago
parent
commit
f976c951ae

+ 3
- 0
changelog.txt View File

@@ -1,3 +1,6 @@
rc2 (0.2.1):
+ Vanilla redstone now connects properly to Ender Transmitters and Receivers.

rc1 (0.2.0):
+ Add Endpoints! They are extra pathnames you specify on the end of the address
/ For example: "local.2/path"

+ 19
- 2
pl/asie/endernet/api/IEnderRedstone.java View File

@@ -1,6 +1,23 @@
package pl.asie.endernet.api;

public interface IEnderRedstone {
public int getRedstone();
public boolean setRedstone(int value);
/**
* Get the entity's redstone value.
* @return The public-facing redstone value.
*/
public int getRedstoneValue();
/**
* Set the redstone value.
* @param value Current redstone value.
* @return Whether the internal value changed.
*/
public boolean setRedstoneValue(int value);
/**
* Set the redstone value if received externally.
* @param value New redstone value.
* @return Whether the internal value changed.
*/
public boolean receiveRedstoneValue(int value);
}

+ 122
- 0
pl/asie/endernet/block/BlockBase.java View File

@@ -0,0 +1,122 @@
package pl.asie.endernet.block;

import pl.asie.endernet.EnderNet;
import powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet;
import powercrystals.minefactoryreloaded.api.rednet.RedNetConnectionType;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;

public abstract class BlockBase extends BlockContainer implements IConnectableRedNet {
private boolean canConnectRedstone;
protected BlockBase(int id, boolean connectsToRedstone) {
super(id, Material.iron);
this.setCreativeTab(CreativeTabs.tabMisc);
this.setHardness(1.5F);
this.canConnectRedstone = connectsToRedstone;
}
// DESTROY HANDLERS
public void onBlockDestroyed(World world, int x, int y, int z, int meta) {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity != null) {
tileEntity.invalidate();
}
}

@Override
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) {
super.onBlockDestroyedByPlayer(world, x, y, z, meta);
this.onBlockDestroyed(world, x, y, z, meta);
}

@Override
public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) {
super.onBlockDestroyedByExplosion(world, x, y, z, explosion);
this.onBlockDestroyed(world, x, y, z, 0);
}
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta) {
this.onBlockDestroyed(world, x, y, z, meta);
super.breakBlock(world, x, y, z, id, meta);
}
// REDSTONE CODE
// Helpers
private void setRedstone(World world, int x, int y, int z, int value) {
TileEntity entity = world.getBlockTileEntity(x, y, z);
if(!(entity instanceof TileEntityEnder)) return;
((TileEntityEnder)entity).setRedstoneValue(value);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int side) {
if(canConnectRedstone) setRedstone(world, x, y, z, this.getWorldRedstoneValue(world, x, y, z));
}
// Vanilla redstone
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return canConnectRedstone;
}
public int getWorldRedstoneValue(World world, int x, int y, int z) {
return (world.isBlockIndirectlyGettingPowered(x, y, z) ? 1 : 0);
}

@Override
public boolean canProvidePower() { return canConnectRedstone; }
@Override
public int isProvidingWeakPower(IBlockAccess access, int x, int y, int z, int side) {
TileEntityEnder entity = (TileEntityEnder)access.getBlockTileEntity(x, y, z);
return entity.getRedstoneValue() > 0 ? 15 : 0;
}

// MineFactory Reloaded
@Override
/**
* Override this function if you receive or transmit in the TileEntity.
*/
public RedNetConnectionType getConnectionType(World world, int x, int y,
int z, ForgeDirection side) {
return canConnectRedstone ? RedNetConnectionType.CableSingle : RedNetConnectionType.None;
}

@Override
public int[] getOutputValues(World world, int x, int y, int z,
ForgeDirection side) {
return null;
}

@Override
public int getOutputValue(World world, int x, int y, int z,
ForgeDirection side, int subnet) {
TileEntityEnder entity = (TileEntityEnder)world.getBlockTileEntity(x, y, z);
return entity.getRedstoneValue();
}

@Override
public void onInputsChanged(World world, int x, int y, int z,
ForgeDirection side, int[] inputValues) {
}
@Override
public void onInputChanged(World world, int x, int y, int z,
ForgeDirection side, int inputValue) {
if(canConnectRedstone) setRedstone(world, x, y, z, inputValue);
}
public boolean canConnectRedstone() { return canConnectRedstone; }
}

+ 7
- 57
pl/asie/endernet/block/BlockEnder.java View File

@@ -21,15 +21,14 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;

public class BlockEnder extends BlockContainer implements IConnectableRedNet {
public BlockEnder(int id) {
super(id, Material.iron);
this.setCreativeTab(CreativeTabs.tabMisc);
this.setHardness(1.5F);
public class BlockEnder extends BlockBase {
public BlockEnder(int id, boolean connectsToRedstone) {
super(id, connectsToRedstone);
}
@Override
@@ -46,7 +45,7 @@ public class BlockEnder extends BlockContainer implements IConnectableRedNet {
ChatMessageComponent chat = new ChatMessageComponent();
TileEntityEnder ender = (TileEntityEnder)world.getBlockTileEntity(x, y, z);
if(!ender.canReceive()) chat.addKey("error.endernet.dimension");
else chat.addFormatted("info.endernet.id", new Object[]{""+ender.enderNetID});
else chat.addFormatted("info.endernet.id", new Object[]{""+ender.getEnderNetID()});
player.sendChatToPlayer(chat);
}
return true;
@@ -64,7 +63,7 @@ public class BlockEnder extends BlockContainer implements IConnectableRedNet {
ItemStack item = new ItemStack(this, 1);
NBTTagCompound enderData = item.getTagCompound();
if(enderData == null) enderData = new NBTTagCompound();
enderData.setInteger("eid", ender.enderNetID);
enderData.setInteger("eid", ender.getEnderNetID());

this.breakBlock(world, x, y, z, this.blockID, 0);
world.setBlockToAir(x, y, z);
@@ -73,6 +72,7 @@ public class BlockEnder extends BlockContainer implements IConnectableRedNet {
}
}

@Override
public void onBlockDestroyed(World world, int x, int y, int z, int meta) {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity != null) {
@@ -80,54 +80,4 @@ public class BlockEnder extends BlockContainer implements IConnectableRedNet {
tileEntity.invalidate();
}
}

@Override
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) {
super.onBlockDestroyedByPlayer(world, x, y, z, meta);
this.onBlockDestroyed(world, x, y, z, meta);
}

@Override
public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) {
super.onBlockDestroyedByExplosion(world, x, y, z, explosion);
this.onBlockDestroyed(world, x, y, z, 0);
}
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta) {
this.onBlockDestroyed(world, x, y, z, meta);
super.breakBlock(world, x, y, z, id, meta);
}
public int getRedstoneValue(World world, int x, int y, int z) {
return (world.isBlockIndirectlyGettingPowered(x, y, z) ? 1 : 0);
}

@Override
public RedNetConnectionType getConnectionType(World world, int x, int y,
int z, ForgeDirection side) {
return RedNetConnectionType.None;
}

@Override
public int[] getOutputValues(World world, int x, int y, int z,
ForgeDirection side) {
return null;
}

@Override
public int getOutputValue(World world, int x, int y, int z,
ForgeDirection side, int subnet) {
return 0;
}

@Override
public void onInputsChanged(World world, int x, int y, int z,
ForgeDirection side, int[] inputValues) {
}

@Override
public void onInputChanged(World world, int x, int y, int z,
ForgeDirection side, int inputValue) {
}
}

+ 1
- 1
pl/asie/endernet/block/BlockEnderChatBox.java View File

@@ -14,7 +14,7 @@ import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class BlockEnderChatBox extends BlockEnder {
public class BlockEnderChatBox extends BlockEnderModem {
private Icon iconTop, iconSide;
public BlockEnderChatBox(int id) {

+ 1
- 1
pl/asie/endernet/block/BlockEnderModem.java View File

@@ -18,7 +18,7 @@ public class BlockEnderModem extends BlockEnder {
private Icon iconTop, iconSide;
public BlockEnderModem(int id) {
super(id);
super(id, false);
this.setTextureName("endernet:ender_modem");
this.setUnlocalizedName("endernet.enderModem");
}

+ 1
- 29
pl/asie/endernet/block/BlockEnderReceiver.java View File

@@ -22,7 +22,7 @@ public class BlockEnderReceiver extends BlockEnder {
private Icon iconTop, iconSide;
public BlockEnderReceiver(int id) {
super(id);
super(id, true);
this.setTextureName("endernet:ender_receiver");
this.setUnlocalizedName("endernet.enderReceiver");
}
@@ -44,32 +44,4 @@ public class BlockEnderReceiver extends BlockEnder {
iconTop = reg.registerIcon("endernet:ender_receiver_top");
iconSide = reg.registerIcon("endernet:ender_receiver_side");
}
@Override
public boolean canProvidePower() { return true; }
@Override
public int isProvidingWeakPower(IBlockAccess access, int x, int y, int z, int side) {
TileEntityEnderReceiver entity = (TileEntityEnderReceiver)access.getBlockTileEntity(x, y, z);
return entity.getRedstone() > 0 ? 15 : 0;
}

@Override
public RedNetConnectionType getConnectionType(World world, int x, int y,
int z, ForgeDirection side) {
return RedNetConnectionType.CableSingle;
}

@Override
public int[] getOutputValues(World world, int x, int y, int z,
ForgeDirection side) {
return null;
}

@Override
public int getOutputValue(World world, int x, int y, int z,
ForgeDirection side, int subnet) {
TileEntityEnderReceiver entity = (TileEntityEnderReceiver)world.getBlockTileEntity(x, y, z);
return entity.getRedstone();
}
}

+ 1
- 24
pl/asie/endernet/block/BlockEnderTransmitter.java View File

@@ -20,7 +20,7 @@ public class BlockEnderTransmitter extends BlockEnder{
private Icon iconTop, iconSide;
public BlockEnderTransmitter(int id) {
super(id);
super(id, true);
this.setTextureName("endernet:ender_transmitter");
this.setUnlocalizedName("endernet.enderTransmitter");
}
@@ -51,27 +51,4 @@ public class BlockEnderTransmitter extends BlockEnder{
iconTop = reg.registerIcon("endernet:ender_transmitter_top");
iconSide = reg.registerIcon("endernet:ender_transmitter_side");
}
private void setRedstone(World world, int x, int y, int z, int value) {
TileEntity entity = world.getBlockTileEntity(x, y, z);
if(!(entity instanceof TileEntityEnderTransmitter)) return;
((TileEntityEnderTransmitter)entity).sendRedstone(value);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int side) {
setRedstone(world, x, y, z, this.getRedstoneValue(world, x, y, z));
}
@Override
public RedNetConnectionType getConnectionType(World world, int x, int y,
int z, ForgeDirection side) {
return RedNetConnectionType.CableSingle;
}
@Override
public void onInputChanged(World world, int x, int y, int z,
ForgeDirection side, int inputValue) {
setRedstone(world, x, y, z, inputValue);
}
}

+ 2
- 2
pl/asie/endernet/block/GuiEnderTransmitter.java View File

@@ -68,7 +68,7 @@ public class GuiEnderTransmitter extends GuiContainer {
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
this.drawString(this.fontRenderer, "ID " + transmitter.enderNetID, 6, 6, 16777215);
this.drawString(this.fontRenderer, "ID " + transmitter.getEnderNetID(), 6, 6, 16777215);
}

public void syncNBTFromClient(NBTTagCompound data) {
@@ -83,7 +83,7 @@ public class GuiEnderTransmitter extends GuiContainer {
DataOutputStream data = new DataOutputStream(baos);
try {
data.writeByte((byte)1);
data.writeInt(transmitter.enderNetID);
data.writeInt(transmitter.getEnderNetID());
data.writeUTF(this.address.getText());
PacketDispatcher.sendPacketToServer(new Packet250CustomPayload("EnderNet", baos.toByteArray()));
} catch(Exception e) { e.printStackTrace(); }

+ 1
- 1
pl/asie/endernet/block/ItemBlockEnder.java View File

@@ -34,7 +34,7 @@ public class ItemBlockEnder extends ItemBlock {
ender.yCoord = y;
ender.zCoord = z;
ender.worldObj = world;
ender.putEnderID(stack.getTagCompound().getInteger("eid"));
ender.initWithEnderID(stack.getTagCompound().getInteger("eid"));
world.setBlockTileEntity(x, y, z, ender);
}
return true;

+ 68
- 0
pl/asie/endernet/block/TileEntityBase.java View File

@@ -0,0 +1,68 @@
package pl.asie.endernet.block;

import mods.immibis.redlogic.api.wiring.IBundledEmitter;
import mods.immibis.redlogic.api.wiring.IBundledUpdatable;
import mods.immibis.redlogic.api.wiring.IBundledWire;
import mods.immibis.redlogic.api.wiring.IConnectable;
import mods.immibis.redlogic.api.wiring.IWire;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;

public abstract class TileEntityBase extends TileEntity implements IBundledEmitter, IBundledUpdatable, IConnectable {
private int redstoneValue = 0;
public abstract boolean canConnectRedstone();
public abstract int getRedstoneValue();
public abstract boolean setRedstoneValue(int value);
protected int getRedstoneInternal() {
return this.redstoneValue;
}
protected void setRedstoneInternal(int value) {
this.redstoneValue = value;
}

// RedLogic compatibility
@Override
public boolean connects(IWire wire, int blockFace, int fromDirection) {
return canConnectRedstone();
}

@Override
public boolean connectsAroundCorner(IWire wire, int blockFace,
int fromDirection) {
return false;
}

@Override
public byte[] getBundledCableStrength(int blockFace, int toDirection) {
byte[] values = new byte[16];
for(int i = 0; i < 16; i++) {
values[i] = (getRedstoneValue() & (1<<i)) > 0 ? (byte)255 : (byte)0;
}
return values;
}
@Override
public void onBundledInputChanged() {
for(ForgeDirection dir: ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = worldObj.getBlockTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ);
if(te instanceof IBundledWire) {
IBundledWire wire = (IBundledWire)te;
for(int face = -1; face < 6; face++) {
if(wire.wireConnectsInDirection(face, dir.ordinal())) {
int value = 0;
byte[] data = wire.getBundledCableStrength(face, dir.ordinal());
for(int i = 0; i < 16; i++) {
if(data[i] != 0) value |= 1<<i;
}
setRedstoneValue(value);
return;
}
}
}
}
}
}

+ 54
- 38
pl/asie/endernet/block/TileEntityEnder.java View File

@@ -3,37 +3,81 @@ package pl.asie.endernet.block;
import java.util.ArrayList;
import java.util.HashSet;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
import pl.asie.endernet.EnderNet;
import pl.asie.endernet.api.IEnderRedstone;
import mods.immibis.redlogic.api.wiring.IBundledEmitter;
import mods.immibis.redlogic.api.wiring.IBundledUpdatable;
import mods.immibis.redlogic.api.wiring.IBundledWire;
import mods.immibis.redlogic.api.wiring.IConnectable;
import mods.immibis.redlogic.api.wiring.IWire;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;

public class TileEntityEnder extends TileEntity implements IEnderRedstone, IPeripheral, IConnectable {
public int enderNetID = -1;
public class TileEntityEnder extends TileEntityBase implements IEnderRedstone, IPeripheral {
private int enderNetID = -1;
protected String address = "local.0";

// API functions
public boolean canConnectRedstone() {
return ((BlockEnder)getBlockType()).canConnectRedstone();
}
public boolean canTransmit() {
return !EnderNet.isDimensionBlacklisted(this.worldObj.provider.dimensionId);
}
public boolean canReceive() {
return !EnderNet.isDimensionBlacklisted(this.worldObj.provider.dimensionId);
}
public String getAddress() { return address; }
public void setAddress(String address) {
this.address = address;
}
@Override
public int getRedstoneValue() {
return 0;
}

@Override
public boolean setRedstoneValue(int value) {
return false;
}
@Override
public boolean receiveRedstoneValue(int value) {
return false;
}
public int getEnderNetID() {
return enderNetID;
}
@SideOnly(Side.CLIENT)
public void setEnderNetIDClient(int id) {
enderNetID = id;
}
protected void initWithEnderID(int eid) {
enderNetID = EnderNet.registry.forceEntityID(this, eid);
}
// Minecraft functions
@Override
public void updateEntity() {
super.updateEntity();
if(!this.worldObj.isRemote && enderNetID == -1) enderNetID = EnderNet.registry.getEntityID(this);
}
protected void writeNBTEnderData(NBTTagCompound tagCompound) {
tagCompound.setInteger("eid", enderNetID);
tagCompound.setString("a", address);
}

@Override
public void readFromNBT(NBTTagCompound tagCompound) {
@@ -49,12 +93,9 @@ public class TileEntityEnder extends TileEntity implements IEnderRedstone, IPeri
writeNBTEnderData(tagCompound);
}
public boolean canTransmit() {
return !EnderNet.isDimensionBlacklisted(this.worldObj.provider.dimensionId);
}
public boolean canReceive() {
return !EnderNet.isDimensionBlacklisted(this.worldObj.provider.dimensionId);
protected void writeNBTEnderData(NBTTagCompound tagCompound) {
tagCompound.setInteger("eid", enderNetID);
tagCompound.setString("a", address);
}
// COMPUTERCRAFT COMPATIBILITY BEGIN
@@ -112,29 +153,4 @@ public class TileEntityEnder extends TileEntity implements IEnderRedstone, IPeri
public void detach(IComputerAccess computer) {
computers.remove(computer);
}
@Override
public boolean setRedstone(int value) {
return false;
}

@Override
public int getRedstone() {
return 0;
}

@Override
public boolean connects(IWire wire, int blockFace, int fromDirection) {
return true;
}

@Override
public boolean connectsAroundCorner(IWire wire, int blockFace,
int fromDirection) {
return false;
}
public void putEnderID(int eid) {
enderNetID = EnderNet.registry.forceEntityID(this, eid);
}
}

+ 1
- 1
pl/asie/endernet/block/TileEntityEnderChatBox.java View File

@@ -25,7 +25,7 @@ public class TileEntityEnderChatBox extends TileEntityEnderModem {
ChatMessageComponent chat = new ChatMessageComponent();
chat.setColor(EnumChatFormatting.GRAY);
chat.setItalic(true);
chat.addText(EnumChatFormatting.ITALIC + "[ChatBox "+this.enderNetID+"] ");
chat.addText(EnumChatFormatting.ITALIC + "[ChatBox "+this.getEnderNetID()+"] ");
chat.addText(EnumChatFormatting.RESET + "" + EnumChatFormatting.GRAY + string);
for(Object o: this.worldObj.playerEntities) {
if(!(o instanceof EntityPlayer)) continue;

+ 1
- 1
pl/asie/endernet/block/TileEntityEnderModem.java View File

@@ -66,7 +66,7 @@ public class TileEntityEnderModem extends TileEntityEnder implements IEnderStrin
public String[] getMethodNames() {
String[] names;
if(CAN_TRANSMIT_MODEM) names = new String[]{ "getAddress", "setAddress", "getID", "canReceive", "canTransmit", "send" };
else names = new String[]{ "getAddress", "setAddress", "getID", "canReceive", "canTransmit" };
else names = new String[]{ "getAddress", "setAddress", "getID", "canReceive", "canTransmit", "" };
return names;
}

+ 8
- 18
pl/asie/endernet/block/TileEntityEnderReceiver.java View File

@@ -17,8 +17,7 @@ import pl.asie.endernet.lib.EnderID;
import pl.asie.endernet.lib.EnderServer;
import pl.asie.endernet.lib.MiscUtils;

public class TileEntityEnderReceiver extends TileEntityEnderModem implements IBundledEmitter, IEnderRedstone, IEnderStringReceiver, IInventory {
private int redstoneValue;
public class TileEntityEnderReceiver extends TileEntityEnderModem implements IEnderRedstone, IEnderStringReceiver, IInventory {
private boolean updateNextTick;

public TileEntityEnderReceiver() {
@@ -181,23 +180,14 @@ public class TileEntityEnderReceiver extends TileEntityEnderModem implements IBu
}

@Override
public boolean setRedstone(int value) {
this.redstoneValue = value;
this.updateNextTick = true;
return true;
}

@Override
public int getRedstone() {
return redstoneValue;
public int getRedstoneValue() {
return this.getRedstoneInternal();
}
@Override
public byte[] getBundledCableStrength(int blockFace, int toDirection) {
byte[] values = new byte[16];
for(int i = 0; i < 16; i++) {
values[i] = (this.redstoneValue & (1<<i)) > 0 ? (byte)255 : (byte)0;
}
return values;
public boolean receiveRedstoneValue(int value) {
this.setRedstoneInternal(value);
this.updateNextTick = true;
return true;
}
}

+ 9
- 36
pl/asie/endernet/block/TileEntityEnderTransmitter.java View File

@@ -27,7 +27,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection;

public class TileEntityEnderTransmitter extends TileEntityEnderModem implements IInventory, IBundledUpdatable {
public class TileEntityEnderTransmitter extends TileEntityEnderModem implements IInventory {
public TileEntityEnderTransmitter() {
super(false, true); // transmit only
}
@@ -129,7 +129,7 @@ public class TileEntityEnderTransmitter extends TileEntityEnderModem implements
entity.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
entity.startSending = true;
} else if(action == 3) {
EnderRedirector.sendRedstone(entity.address, entity.rsValue);
EnderRedirector.sendRedstone(entity.address, entity.getRedstoneInternal());
}
}
}
@@ -256,7 +256,7 @@ public class TileEntityEnderTransmitter extends TileEntityEnderModem implements
this.spawnSuccessParticles();
break;
}
this.enderNetID = packet.data.getInteger("eid");
this.setEnderNetIDClient(packet.data.getInteger("eid"));
this.isReceiveable = packet.data.getBoolean("r");
GuiScreen gui = FMLClientHandler.instance().getClient().currentScreen;
if (gui != null && gui instanceof GuiEnderTransmitter) {
@@ -327,41 +327,14 @@ public class TileEntityEnderTransmitter extends TileEntityEnderModem implements
}
return null;
}
private int rsValue = 0;

public void sendRedstone(int value) {
if(rsValue == value) return; // already sent
rsValue = value;
@Override
public boolean setRedstoneValue(int value) {
System.out.println("Setting value " + value);
if(this.getRedstoneInternal() == value) return false; // already sent
this.setRedstoneInternal(value);
ReceiveThread rt = new ReceiveThread(this, 3);
rt.start();
}
// REDLOGIC COMPATIBILITY

@Override
public void onBundledInputChanged() {
// Immibis, please, get a better API.
for(ForgeDirection dir: ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = worldObj.getBlockTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ);
if(te instanceof IBundledWire) {
IBundledWire wire = (IBundledWire)te;
byte[] data = null;
for(int i = -1; i < 6; i++) {
if(wire.wireConnectsInDirection(i, (dir.ordinal()))) {
data = wire.getBundledCableStrength(i, (dir.ordinal()));
break;
}
}
if(data != null) {
int value = 0;
for(int i = 0; i < 16; i++) {
if(data[i] != 0) value |= 1<<i;
}
System.out.println(value);
this.sendRedstone(value);
}
}
}
return true;
}
}

+ 1
- 1
pl/asie/endernet/http/URIHandlerSendRedstone.java View File

@@ -28,7 +28,7 @@ public class URIHandlerSendRedstone implements IURIHandler {
TileEntity entity = EnderNet.registry.getTileEntity(target);
if(entity == null || !(entity instanceof IEnderRedstone)) return false;
IEnderRedstone receiver = (IEnderRedstone)entity;
return new HTTPResponse(receiver.setRedstone(new Integer(params.get("value")).intValue()));
return new HTTPResponse(receiver.receiveRedstoneValue(new Integer(params.get("value")).intValue()));
}
@Override

Loading…
Cancel
Save