Fixed force field projector state rendering

Improved force field relay and projector rendering when not connected
This commit is contained in:
LemADEC 2017-08-14 19:25:26 +02:00
parent 0d04eaaf1f
commit 3e0e4d4874
5 changed files with 74 additions and 64 deletions

View file

@ -64,17 +64,18 @@ public class BlockForceFieldProjector extends BlockAbstractForceField {
return icons[0];
}
if (side == (metadata & 7) || (((TileEntityForceFieldProjector)tileEntity).isDoubleSided && ForgeDirection.OPPOSITES[side] == (metadata & 7))) {
return icons[3 + ((TileEntityForceFieldProjector)tileEntity).getShape().ordinal()];
} else if (((TileEntityForceFieldProjector)tileEntity).isConnected) {
if (((TileEntityForceFieldProjector)tileEntity).isPowered) {
return icons[2];
} else {
return icons[1];
}
if (side == (metadata & 7) || (((TileEntityForceFieldProjector) tileEntity).isDoubleSided && ForgeDirection.OPPOSITES[side] == (metadata & 7))) {
return icons[3 + ((TileEntityForceFieldProjector) tileEntity).getShape().ordinal()];
}
if ( !((TileEntityForceFieldProjector) tileEntity).isConnected
|| !((TileEntityForceFieldProjector) tileEntity).isEnabled ) {
return icons[0];
}
if (!((TileEntityForceFieldProjector) tileEntity).isPowered) {
return icons[1];
}
return icons[0];
return icons[2];
}
@SideOnly(Side.CLIENT)

View file

@ -56,7 +56,10 @@ public class BlockForceFieldRelay extends BlockAbstractForceField {
if (side == 0 || side == 1) {
return icons[EnumForceFieldUpgrade.length];
}
return icons[((TileEntityForceFieldRelay)tileEntity).getUpgrade().ordinal()];
if (((TileEntityForceFieldRelay) tileEntity).isConnected){
return icons[((TileEntityForceFieldRelay) tileEntity).getUpgrade().ordinal()];
}
return icons[EnumForceFieldUpgrade.NONE.ordinal()];
}
@SideOnly(Side.CLIENT)

View file

@ -31,7 +31,7 @@ public class TileEntityAbstractForceField extends TileEntityAbstractEnergy imple
// computed properties
protected Vector3 vRGB;
protected boolean isConnected = true;
protected boolean isConnected = false;
public TileEntityAbstractForceField() {
super();
@ -64,7 +64,11 @@ public class TileEntityAbstractForceField extends TileEntityAbstractEnergy imple
}
// Frequency is not set
isConnected = beamFrequency > 0 && beamFrequency <= IBeamFrequency.BEAM_FREQUENCY_MAX;
final boolean new_isConnected = beamFrequency > 0 && beamFrequency <= IBeamFrequency.BEAM_FREQUENCY_MAX;
if (isConnected != new_isConnected) {
isConnected = new_isConnected;
markDirty();
}
}
@Override
@ -125,21 +129,22 @@ public class TileEntityAbstractForceField extends TileEntityAbstractEnergy imple
tier = tagCompound.getByte("tier");
setBeamFrequency(tagCompound.getInteger(BEAM_FREQUENCY_TAG));
isEnabled = !tagCompound.hasKey("isEnabled") || tagCompound.getBoolean("isEnabled");
isConnected = tagCompound.getBoolean("isConnected");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setByte("tier", tier);
tag.setInteger(BEAM_FREQUENCY_TAG, beamFrequency);
tag.setBoolean("isEnabled", isEnabled);
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setByte("tier", tier);
tagCompound.setInteger(BEAM_FREQUENCY_TAG, beamFrequency);
tagCompound.setBoolean("isEnabled", isEnabled);
tagCompound.setBoolean("isConnected", isConnected);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tagCompound = new NBTTagCompound();
writeToNBT(tagCompound);
tagCompound.setBoolean("isConnected", isConnected);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound);
}
@ -147,7 +152,6 @@ public class TileEntityAbstractForceField extends TileEntityAbstractEnergy imple
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
NBTTagCompound tagCompound = packet.func_148857_g();
readFromNBT(tagCompound);
isConnected = tagCompound.getBoolean("isConnected");
}
// OpenComputer callback methods

View file

@ -175,7 +175,11 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
if (energyRequired > energy_getMaxStorage()) {
WarpDrive.logger.error("Force field projector requires " + energyRequired + " to get started but can only store " + energy_getMaxStorage());
}
isPowered = energy_getEnergyStored() >= energyRequired;
final boolean new_isPowered = energy_getEnergyStored() >= energyRequired;
if (isPowered != new_isPowered) {
isPowered = new_isPowered;
markDirty();
}
boolean isEnabledAndValid = isEnabled && isValid();
boolean isOn = isEnabledAndValid && cooldownTicks <= 0 && isPowered;
@ -880,82 +884,82 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
isDoubleSided = tag.getBoolean("isDoubleSided");
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
isDoubleSided = tagCompound.getBoolean("isDoubleSided");
if (tag.hasKey("minX")) {
setMin(tag.getFloat("minX"), tag.getFloat("minY"), tag.getFloat("minZ"));
if (tagCompound.hasKey("minX")) {
setMin(tagCompound.getFloat("minX"), tagCompound.getFloat("minY"), tagCompound.getFloat("minZ"));
} else {
setMin(-1.0F, -1.0F, -1.0F);
}
if (tag.hasKey("maxX")) {
setMax(tag.getFloat("maxX"), tag.getFloat("maxY"), tag.getFloat("maxZ"));
if (tagCompound.hasKey("maxX")) {
setMax(tagCompound.getFloat("maxX"), tagCompound.getFloat("maxY"), tagCompound.getFloat("maxZ"));
} else {
setMax(1.0F, 1.0F, 1.0F);
}
setRotation(tag.getFloat("rotationYaw"), tag.getFloat("rotationPitch"), tag.getFloat("rotationRoll"));
setRotation(tagCompound.getFloat("rotationYaw"), tagCompound.getFloat("rotationPitch"), tagCompound.getFloat("rotationRoll"));
setShape(EnumForceFieldShape.get(tag.getByte("shape")));
setShape(EnumForceFieldShape.get(tagCompound.getByte("shape")));
setTranslation(tag.getFloat("translationX"), tag.getFloat("translationY"), tag.getFloat("translationZ"));
setTranslation(tagCompound.getFloat("translationX"), tagCompound.getFloat("translationY"), tagCompound.getFloat("translationZ"));
legacy_isOn = tag.getBoolean("isOn");
legacy_isOn = tagCompound.getBoolean("isOn");
isPowered = tagCompound.getBoolean("isPowered");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setBoolean("isDoubleSided", isDoubleSided);
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setBoolean("isDoubleSided", isDoubleSided);
if (v3Min.x != -1.0D || v3Min.y != -1.0D || v3Min.z != -1.0D) {
tag.setFloat("minX", (float)v3Min.x);
tag.setFloat("minY", (float)v3Min.y);
tag.setFloat("minZ", (float)v3Min.z);
tagCompound.setFloat("minX", (float)v3Min.x);
tagCompound.setFloat("minY", (float)v3Min.y);
tagCompound.setFloat("minZ", (float)v3Min.z);
}
if (v3Max.x != 1.0D || v3Max.y != 1.0D || v3Max.z != 1.0D) {
tag.setFloat("maxX", (float)v3Max.x);
tag.setFloat("maxY", (float)v3Max.y);
tag.setFloat("maxZ", (float)v3Max.z);
tagCompound.setFloat("maxX", (float)v3Max.x);
tagCompound.setFloat("maxY", (float)v3Max.y);
tagCompound.setFloat("maxZ", (float)v3Max.z);
}
if (rotationYaw != 0.0F) {
tag.setFloat("rotationYaw", rotationYaw);
tagCompound.setFloat("rotationYaw", rotationYaw);
}
if (rotationPitch != 0.0F) {
tag.setFloat("rotationPitch", rotationPitch);
tagCompound.setFloat("rotationPitch", rotationPitch);
}
if (rotationRoll != 0.0F) {
tag.setFloat("rotationRoll", rotationRoll);
tagCompound.setFloat("rotationRoll", rotationRoll);
}
tag.setByte("shape", (byte) getShape().ordinal());
tagCompound.setByte("shape", (byte) getShape().ordinal());
if (v3Translation.x != 0.0D || v3Translation.y != 0.0D || v3Translation.z != 0.0D) {
tag.setFloat("translationX", (float)v3Translation.x);
tag.setFloat("translationY", (float)v3Translation.y);
tag.setFloat("translationZ", (float)v3Translation.z);
tagCompound.setFloat("translationX", (float)v3Translation.x);
tagCompound.setFloat("translationY", (float)v3Translation.y);
tagCompound.setFloat("translationZ", (float)v3Translation.z);
}
tag.setBoolean("isOn", legacy_isOn);
tagCompound.setBoolean("isOn", legacy_isOn);
tagCompound.setBoolean("isPowered", isPowered);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tagCompound = new NBTTagCompound();
final NBTTagCompound tagCompound = new NBTTagCompound();
writeToNBT(tagCompound);
tagCompound.setBoolean("isConnected", isConnected);
tagCompound.setBoolean("isPowered", isPowered);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound);
}
@Override
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
NBTTagCompound tagCompound = packet.func_148857_g();
final NBTTagCompound tagCompound = packet.func_148857_g();
readFromNBT(tagCompound);
isPowered = tagCompound.getBoolean("isPowered");
isConnected = tagCompound.getBoolean("isConnected");
}
public ForceFieldSetup getForceFieldSetup() {

View file

@ -56,30 +56,28 @@ public class TileEntityForceFieldRelay extends TileEntityAbstractForceField impl
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
setUpgrade(EnumForceFieldUpgrade.get(tag.getByte("upgrade")));
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
setUpgrade(EnumForceFieldUpgrade.get(tagCompound.getByte("upgrade")));
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setByte("upgrade", (byte) getUpgrade().ordinal());
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setByte("upgrade", (byte) getUpgrade().ordinal());
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tagCompound = new NBTTagCompound();
final NBTTagCompound tagCompound = new NBTTagCompound();
writeToNBT(tagCompound);
tagCompound.setBoolean("isConnected", isConnected);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound);
}
@Override
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
NBTTagCompound tagCompound = packet.func_148857_g();
final NBTTagCompound tagCompound = packet.func_148857_g();
readFromNBT(tagCompound);
isConnected = tagCompound.getBoolean("isConnected");
}
@Override