Skip to content

Commit

Permalink
Fix gates not saving their io, leftover from the FMP separation, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Mar 10, 2015
1 parent 1afc737 commit ab89fe1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
42 changes: 37 additions & 5 deletions src/main/java/vic/mod/integratedcircuits/gate/PartGate.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package vic.mod.integratedcircuits.gate;

import java.util.Arrays;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;

import org.apache.commons.lang3.ArrayUtils;

import vic.mod.integratedcircuits.Constants;
import vic.mod.integratedcircuits.IntegratedCircuits;
import vic.mod.integratedcircuits.client.PartGateRenderer;
Expand Down Expand Up @@ -72,12 +77,44 @@ public void load(NBTTagCompound tag)
{
orientation = tag.getByte("orientation");
io = tag.getByte("io");

byte[] input = tag.getByteArray("input");
byte[] output = tag.getByteArray("output");

try {
for(int i = 0; i < 4; i++)
{
this.input[i] = Arrays.copyOfRange(input, i * 16, (i + 1) * 16);
this.output[i] = Arrays.copyOfRange(output, i * 16, (i + 1) * 16);
}
} catch (ArrayIndexOutOfBoundsException e) {
//--Legacy code--
//We couldn't get a proper array, so output a warning.
IntegratedCircuits.logger.warn("Couldn't retrieve gate io for circuit at " + getProvider().getPos() + ". "
+ "This can be caused by a version update, if this happens on the next world load please report it!");

//Reset to old configuration
this.input = new byte[4][16];
this.output = new byte[4][16];
}
}

public void save(NBTTagCompound tag)
{
tag.setByte("orientation", orientation);
tag.setByte("io", io);

byte[] input = null;
byte[] output = null;

for(int i = 0; i < 4; i++)
{
input = ArrayUtils.addAll(input, this.input[i]);
output = ArrayUtils.addAll(output, this.output[i]);
}

tag.setByteArray("input", input);
tag.setByteArray("output", output);
}

public void readDesc(MCDataInput packet)
Expand Down Expand Up @@ -175,11 +212,6 @@ public void onAdded()
notifyChanges();
}

public void onWorldJoin()
{
notifyChanges();
}

public void onRemoved()
{
provider.notifyBlocksAndChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ public void onAdded()
gate.onAdded();
}

@Override
public void onWorldJoin()
{
gate.onWorldJoin();
}

@Override
public void onRemoved()
{
Expand Down

0 comments on commit ab89fe1

Please sign in to comment.