Pushing data, two way connections

visibileWires
Astoria 2 years ago
parent b0546af597
commit 61475f86ea

@ -3,7 +3,6 @@ package net.brokenmoon.afloydwiremod.api;
import net.brokenmoon.afloydwiremod.WireMod; import net.brokenmoon.afloydwiremod.WireMod;
import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.item.ToolWiring;
import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer;
import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity;
import net.minecraft.src.*; import net.minecraft.src.*;
public abstract class AbstractWireTile extends BlockContainer { public abstract class AbstractWireTile extends BlockContainer {
@ -55,4 +54,8 @@ public abstract class AbstractWireTile extends BlockContainer {
//Singleplayer //Singleplayer
((IEntityPlayer)player).displayGuiSettings(chip); ((IEntityPlayer)player).displayGuiSettings(chip);
} }
@Override
public int getRenderType(){
return 28;
}
} }

@ -75,18 +75,24 @@ public abstract class AbstractWireTileEntity extends TileEntity {
} }
public void updateIO(){ public void updateIO(){
if(inputs != null) { if(outputs != null) {
for (int i = 0; i < inputs.length; ++i) { for (int i = 0; i < outputs.length; ++i) {
if (inputs[i].wire != null && inputs[i].wire.thisslot > -1) { if (outputs[i].wire != null && outputs[i].wire.thisslot > -1) {
WireConnection wire = inputs[i].wire; WireConnection wire = outputs[i].wire;
AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z);
if(otherChip == null) break; if(otherChip == null){
if(otherChip.outputs == null) break; this.outputs[i].wire = new WireConnection();
if(inputs[i].floatvalue != otherChip.outputs[wire.thatslot].floatvalue) { break;
inputs[i].floatvalue = otherChip.outputs[wire.thatslot].floatvalue; }
if(otherChip.outputs == null) {
this.outputs[i].wire = new WireConnection();
break;
}
if(outputs[i].floatvalue != otherChip.inputs[wire.thatslot].floatvalue) {
otherChip.inputs[wire.thatslot].floatvalue = outputs[i].floatvalue;
} }
if(!inputs[i].stringvalue.equals(otherChip.outputs[wire.thatslot].stringvalue)) { if(!outputs[i].stringvalue.equals(otherChip.inputs[wire.thatslot].stringvalue)) {
inputs[i].stringvalue = otherChip.outputs[wire.thatslot].stringvalue; otherChip.inputs[wire.thatslot].stringvalue = outputs[i].stringvalue;
} }
} }
} }

@ -1,9 +1,9 @@
package net.brokenmoon.afloydwiremod.api; package net.brokenmoon.afloydwiremod.api;
import net.brokenmoon.afloydwiremod.gui.WiringButton;
import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagCompound;
public class WireConnection { public class WireConnection {
public boolean isMade;
public int x; public int x;
public int y; public int y;
public int z; public int z;
@ -11,13 +11,7 @@ public class WireConnection {
public int thatslot; public int thatslot;
public WireConnection(){ public WireConnection(){
this.isMade = false;
}
public WireConnection(int x, int y, int z, int thisslot){
this.x = x;
this.y = y;
this.z = z;
this.thisslot = thisslot;
} }
public WireConnection(int x, int y, int z, int thisslot, int thatslot){ public WireConnection(int x, int y, int z, int thisslot, int thatslot){
@ -26,12 +20,14 @@ public class WireConnection {
this.z = z; this.z = z;
this.thisslot = thisslot; this.thisslot = thisslot;
this.thatslot = thatslot; this.thatslot = thatslot;
this.isMade = true;
} }
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("wx", this.x); nbttagcompound.setInteger("wx", this.x);
nbttagcompound.setInteger("wy", this.y); nbttagcompound.setInteger("wy", this.y);
nbttagcompound.setInteger("wz", this.z); nbttagcompound.setInteger("wz", this.z);
nbttagcompound.setBoolean("made", this.isMade);
nbttagcompound.setInteger("wthisslot", thisslot); nbttagcompound.setInteger("wthisslot", thisslot);
nbttagcompound.setInteger("wthatslot", thatslot); nbttagcompound.setInteger("wthatslot", thatslot);
return nbttagcompound; return nbttagcompound;
@ -41,6 +37,7 @@ public class WireConnection {
this.x = nbttagcompound.getInteger("wx"); this.x = nbttagcompound.getInteger("wx");
this.y = nbttagcompound.getInteger("wy"); this.y = nbttagcompound.getInteger("wy");
this.z = nbttagcompound.getInteger("wz"); this.z = nbttagcompound.getInteger("wz");
this.isMade = nbttagcompound.getBoolean("made");
this.thisslot = nbttagcompound.getInteger("wthisslot"); this.thisslot = nbttagcompound.getInteger("wthisslot");
this.thatslot = nbttagcompound.getInteger("wthatslot"); this.thatslot = nbttagcompound.getInteger("wthatslot");
} }

@ -28,7 +28,7 @@ public class GuiButtonExtended extends GuiButton {
FontRenderer fontrenderer = minecraft.fontRenderer; FontRenderer fontrenderer = minecraft.fontRenderer;
GL11.glBindTexture(3553, minecraft.renderEngine.getTexture("/gui/gui.png")); GL11.glBindTexture(3553, minecraft.renderEngine.getTexture("/gui/gui.png"));
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
boolean flag = i >= this.xPosition && j >= this.yPosition && i < this.xPosition + this.width && j < this.yPosition + this.height; boolean flag = i >= this.xPosition && j >= this.yPosition + scroll && i < this.xPosition + this.width && j < this.yPosition + scroll + this.height;
int k = this.getButtonState(flag); int k = this.getButtonState(flag);
this.drawTexturedModalRect(this.xPosition, this.yPosition + scroll, 0, 46 + k * 20, this.width / 2, this.height); this.drawTexturedModalRect(this.xPosition, this.yPosition + scroll, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition + scroll, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height); this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition + scroll, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);

@ -3,14 +3,11 @@ package net.brokenmoon.afloydwiremod.gui;
import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity;
import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity;
import net.minecraft.src.*; import net.minecraft.src.*;
import org.lwjgl.input.Mouse;
public class GuiProgrammer extends GuiScrollable { public class GuiProgrammer extends GuiScrollable {
private AbstractWireTileEntity wireEntity; private AbstractWireTileEntity wireEntity;
private int scroll;
@Override @Override
public void initGui() { public void initGui() {
//this.height - 240 is top //this.height - 240 is top
@ -29,7 +26,6 @@ public class GuiProgrammer extends GuiScrollable {
if(wireEntity instanceof ChipTileEntity) { if(wireEntity instanceof ChipTileEntity) {
if (guibutton.id == 1) { if (guibutton.id == 1) {
((ChipTileEntity) wireEntity).setMode("constant"); ((ChipTileEntity) wireEntity).setMode("constant");
System.out.println("ae");
} else if (guibutton.id == 2) { } else if (guibutton.id == 2) {
((ChipTileEntity) wireEntity).setMode("count"); ((ChipTileEntity) wireEntity).setMode("count");
} }

@ -3,6 +3,7 @@ package net.brokenmoon.afloydwiremod.gui;
import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity;
import net.brokenmoon.afloydwiremod.api.WireConnection; import net.brokenmoon.afloydwiremod.api.WireConnection;
import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.item.ToolWiring;
import net.minecraft.client.Minecraft;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.GuiButton; import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen; import net.minecraft.src.GuiScreen;
@ -20,15 +21,15 @@ public class GuiWiring extends GuiScrollable {
//this.height - 240 is top //this.height - 240 is top
//This.width / 2 - 214 is left //This.width / 2 - 214 is left
//Inputs //Inputs
if(wireEntity.inputs != null && this.tool.type.equals("output")) { if(wireEntity.inputs != null && !this.tool.type.equals("input")) {
for (int i = 0; i < wireEntity.inputs.length; i++) { for (int i = 0; i < wireEntity.inputs.length; i++) {
this.controlList.add(new GuiButtonExtended(i + 1, this.width, wireEntity.inputs[i].buttonString, "Input", wireEntity.inputs[i].slot)); this.controlList.add(new GuiButtonExtended(i + 1, this.width - 50, wireEntity.inputs[i].buttonString, "Input", wireEntity.inputs[i].slot));
} }
} }
//Outputs //Outputs
if(wireEntity.outputs != null && !this.tool.type.equals("output")) { if(wireEntity.outputs != null && !this.tool.type.equals("output")) {
for (int i = 0; i < wireEntity.outputs.length; i++) { for (int i = 0; i < wireEntity.outputs.length; i++) {
this.controlList.add(new GuiButtonExtended(i + 1, this.width, wireEntity.outputs[i].buttonString, "Output", wireEntity.outputs[i].slot)); this.controlList.add(new GuiButtonExtended(i + 1, this.width + 50, wireEntity.outputs[i].buttonString, "Output", wireEntity.outputs[i].slot));
} }
} }
} }
@ -61,9 +62,19 @@ public class GuiWiring extends GuiScrollable {
this.tool.y = y; this.tool.y = y;
this.tool.z = z; this.tool.z = z;
} }
} else if(this.tool.type.equals("output")) { } else if(!this.tool.type.equals("unpaired")) {
this.wireEntity.inputs[guibutton.slot].wire = new WireConnection(tool.x, tool.y, tool.z, guibutton.slot, tool.slot); if(this.tool.type.equals("output")) {
AbstractWireTileEntity otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z);
otherEntity.outputs[guibutton.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot);
Minecraft.getMinecraft().theWorld.markBlocksDirty(x, y, z, x, y, z);
Minecraft.getMinecraft().theWorld.markBlocksDirty(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord);
tool.type = "unpaired"; tool.type = "unpaired";
} else if(this.tool.type.equals("input")) {
this.wireEntity.outputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot);
Minecraft.getMinecraft().theWorld.markBlocksDirty(x, y, z, x, y, z);
Minecraft.getMinecraft().theWorld.markBlocksDirty(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord);
tool.type = "unpaired";
}
} }
this.mc.displayGuiScreen(null); this.mc.displayGuiScreen(null);
} }

@ -0,0 +1,56 @@
package net.brokenmoon.afloydwiremod.mixin;
import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity;
import net.minecraft.src.Block;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.World;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = RenderBlocks.class, remap = false)
public class MixinBlockRenderer {
@Shadow
public boolean renderStandardBlock(Block block, int i, int j, int k) { return false; }
@Shadow
World world;
@Inject(method = "Lnet/minecraft/src/RenderBlocks;renderBlockByRenderType(Lnet/minecraft/src/Block;III)Z", at = @At("HEAD"))
public void injectMethod(Block block, int i, int j, int k, CallbackInfoReturnable<Boolean> cir){
if(block.getRenderType() == 28){
AbstractWireTileEntity wireEntity = (AbstractWireTileEntity)this.world.getBlockTileEntity(i, j, k);
if(wireEntity.outputs != null){
for(int it = 0; it < wireEntity.outputs.length; it++){
if(wireEntity.outputs[it].wire != null && wireEntity.outputs[it].wire.isMade){
this.renderLineBetweenTwoPoints(i, j, k, wireEntity.outputs[it].wire.x, wireEntity.outputs[it].wire.y, wireEntity.outputs[it].wire.z);
}
}
}
this.renderStandardBlock(block, i, j, k);
}
}
public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2, float red, float green, float blue, float alpha, float width){
GL11.glPushMatrix();
GL11.glColor4f(red, green, blue, alpha);
GL11.glLineWidth(width);
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex3f(Math.floorMod(x1, 16l), Math.floorMod(y1, 16l), Math.floorMod(z1, 16l));
GL11.glVertex3f(Math.floorMod(x1, 16l) - (x1 - x2), Math.floorMod(y1, 16l) - (y1 - y2), Math.floorMod(z1, 16l) - (z1 - z2));
GL11.glEnd();
GL11.glPopMatrix();
}
public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2, float red, float green, float blue, float alpha){
renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, red, green, blue, alpha, 1);
}
public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2, float red, float green, float blue){
renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, red, green, blue, 255, 1);
}
public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2){
renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, 255, 0, 0, 255, 5);
}
}

@ -10,12 +10,12 @@ public class ChipTileEntity extends AbstractWireTileEntity {
@Override @Override
public void updateEntity() { public void updateEntity() {
updateIO();
switch (mode) { switch (mode) {
case "count": case "count":
doIncrement(); doIncrement();
break; break;
} }
updateIO();
} }
public void doIncrement() { public void doIncrement() {

@ -32,7 +32,6 @@ public class RedstoneLinkTileEntity extends AbstractWireTileEntity {
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
updateIO();
if(inputs[0].floatvalue > 0 && !this.isActive && worldObj.blockExists(xCoord, yCoord, zCoord) && worldObj.getBlockId(xCoord, yCoord, zCoord) == WireMod.LinkTileInactive.blockID){ if(inputs[0].floatvalue > 0 && !this.isActive && worldObj.blockExists(xCoord, yCoord, zCoord) && worldObj.getBlockId(xCoord, yCoord, zCoord) == WireMod.LinkTileInactive.blockID){
this.shouldnotremove = true; this.shouldnotremove = true;
RedstoneLinkTile.updateLinkBlockState(true, this.worldObj, this.xCoord, this.yCoord, this.zCoord); RedstoneLinkTile.updateLinkBlockState(true, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
@ -44,5 +43,6 @@ public class RedstoneLinkTileEntity extends AbstractWireTileEntity {
this.shouldnotremove = false; this.shouldnotremove = false;
this.isActive = false; this.isActive = false;
} }
updateIO();
} }
} }

@ -4,7 +4,8 @@
"package": "net.brokenmoon.afloydwiremod.mixin", "package": "net.brokenmoon.afloydwiremod.mixin",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"mixins": [ "mixins": [
"MixinEntityPlayerSP" "MixinEntityPlayerSP",
"MixinBlockRenderer"
], ],
"client": [ "client": [
], ],

Loading…
Cancel
Save