yeah these are commits from like a month ago idk what any of this is

This commit is contained in:
BallOfEnergy 2024-10-10 19:44:30 -05:00
parent 88f5ac1cf1
commit 063ab4032f
10 changed files with 482 additions and 449 deletions

View File

@ -7,6 +7,7 @@ import com.google.gson.stream.JsonWriter;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.saveddata.TomSaveData; import com.hbm.saveddata.TomSaveData;
import com.hbm.tileentity.IBufPacketReceiver;
import com.hbm.tileentity.IFluidCopiable; import com.hbm.tileentity.IFluidCopiable;
import com.hbm.tileentity.IConfigurableMachine; import com.hbm.tileentity.IConfigurableMachine;
import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.tileentity.TileEntityLoadedBase;
@ -22,10 +23,10 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
public int age = 0; public int age = 0;
public FluidTank[] tanks; public FluidTank[] tanks;
public int waterTimer = 0; public int waterTimer = 0;
protected int throughput; protected int throughput;
//Configurable values //Configurable values
public static int inputTankSize = 100; public static int inputTankSize = 100;
public static int outputTankSize = 100; public static int outputTankSize = 100;
@ -55,49 +56,49 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
age++; age++;
if(age >= 2) { if(age >= 2) {
age = 0; age = 0;
} }
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
this.tanks[0].writeToNBT(data, "0"); this.tanks[0].writeToNBT(data, "0");
if(this.waterTimer > 0) if(this.waterTimer > 0)
this.waterTimer--; this.waterTimer--;
int convert = Math.min(tanks[0].getFill(), tanks[1].getMaxFill() - tanks[1].getFill()); int convert = Math.min(tanks[0].getFill(), tanks[1].getMaxFill() - tanks[1].getFill());
this.throughput = convert; this.throughput = convert;
if(extraCondition(convert)) { if(extraCondition(convert)) {
tanks[0].setFill(tanks[0].getFill() - convert); tanks[0].setFill(tanks[0].getFill() - convert);
if(convert > 0) if(convert > 0)
this.waterTimer = 20; this.waterTimer = 20;
int light = this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, this.xCoord, this.yCoord, this.zCoord); int light = this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, this.xCoord, this.yCoord, this.zCoord);
if(TomSaveData.forWorld(worldObj).fire > 1e-5 && light > 7) { // Make both steam and water evaporate during firestorms... if(TomSaveData.forWorld(worldObj).fire > 1e-5 && light > 7) { // Make both steam and water evaporate during firestorms...
tanks[1].setFill(tanks[1].getFill() - convert); tanks[1].setFill(tanks[1].getFill() - convert);
} else { } else {
tanks[1].setFill(tanks[1].getFill() + convert); tanks[1].setFill(tanks[1].getFill() + convert);
} }
postConvert(convert); postConvert(convert);
} }
this.tanks[1].writeToNBT(data, "1"); this.tanks[1].writeToNBT(data, "1");
this.subscribeToAllAround(tanks[0].getTankType(), this); this.subscribeToAllAround(tanks[0].getTankType(), this);
this.sendFluidToAll(tanks[1], this); this.sendFluidToAll(tanks[1], this);
sendStandard(150); sendStandard(150);
} }
} }
public void packExtra(NBTTagCompound data) { } public void packExtra(NBTTagCompound data) { }
public boolean extraCondition(int convert) { return true; } public boolean extraCondition(int convert) { return true; }
public void postConvert(int convert) { } public void postConvert(int convert) { }
@ -115,14 +116,14 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
this.tanks[1].deserialize(buf); this.tanks[1].deserialize(buf);
this.waterTimer = buf.readByte(); this.waterTimer = buf.readByte();
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
tanks[0].readFromNBT(nbt, "water"); tanks[0].readFromNBT(nbt, "water");
tanks[1].readFromNBT(nbt, "steam"); tanks[1].readFromNBT(nbt, "steam");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);

View File

@ -50,7 +50,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
public int heat; public int heat;
public int progress; public int progress;
public List<MaterialStack> recipeStack = new ArrayList(); public List<MaterialStack> recipeStack = new ArrayList();
public List<MaterialStack> wasteStack = new ArrayList(); public List<MaterialStack> wasteStack = new ArrayList();
@ -102,21 +102,21 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
tryPullHeat(); tryPullHeat();
/* collect items */ /* collect items */
if(worldObj.getTotalWorldTime() % 5 == 0) { if(worldObj.getTotalWorldTime() % 5 == 0) {
List<EntityItem> list = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord + 0.5, zCoord - 0.5, xCoord + 1.5, yCoord + 1, zCoord + 1.5)); List<EntityItem> list = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord + 0.5, zCoord - 0.5, xCoord + 1.5, yCoord + 1, zCoord + 1.5));
for(EntityItem item : list) { for(EntityItem item : list) {
ItemStack stack = item.getEntityItem(); ItemStack stack = item.getEntityItem();
if(this.isItemSmeltable(stack)) { if(this.isItemSmeltable(stack)) {
for(int i = 1; i < 10; i++) { for(int i = 1; i < 10; i++) {
if(slots[i] == null) { if(slots[i] == null) {
if(stack.stackSize == 1) { if(stack.stackSize == 1) {
slots[i] = stack.copy(); slots[i] = stack.copy();
item.setDead(); item.setDead();
@ -126,7 +126,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
slots[i].stackSize = 1; slots[i].stackSize = 1;
stack.stackSize--; stack.stackSize--;
} }
this.markChanged(); this.markChanged();
} }
} }
@ -139,29 +139,29 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
for(MaterialStack stack : recipeStack) totalMass += stack.amount; for(MaterialStack stack : recipeStack) totalMass += stack.amount;
for(MaterialStack stack : wasteStack) totalMass += stack.amount; for(MaterialStack stack : wasteStack) totalMass += stack.amount;
double level = ((double) totalMass / (double) totalCap) * 0.875D; double level = ((double) totalMass / (double) totalCap) * 0.875D;
List<EntityLivingBase> living = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, xCoord + 0.5, yCoord + 0.5 + level, zCoord + 0.5).expand(1, 0, 1)); List<EntityLivingBase> living = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, xCoord + 0.5, yCoord + 0.5 + level, zCoord + 0.5).expand(1, 0, 1));
for(EntityLivingBase entity : living) { for(EntityLivingBase entity : living) {
entity.attackEntityFrom(DamageSource.lava, 5F); entity.attackEntityFrom(DamageSource.lava, 5F);
entity.setFire(5); entity.setFire(5);
} }
/* smelt items from buffer */ /* smelt items from buffer */
if(!trySmelt()) { if(!trySmelt()) {
this.progress = 0; this.progress = 0;
} }
tryRecipe(); tryRecipe();
/* pour waste stack */ /* pour waste stack */
if(!this.wasteStack.isEmpty()) { if(!this.wasteStack.isEmpty()) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
Vec3 impact = Vec3.createVectorHelper(0, 0, 0); Vec3 impact = Vec3.createVectorHelper(0, 0, 0);
MaterialStack didPour = CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord + 0.25D, zCoord + 0.5D + dir.offsetZ * 1.875D, 6, true, this.wasteStack, MaterialShapes.NUGGET.q(3), impact); MaterialStack didPour = CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord + 0.25D, zCoord + 0.5D + dir.offsetZ * 1.875D, 6, true, this.wasteStack, MaterialShapes.NUGGET.q(3), impact);
if(didPour != null) { if(didPour != null) {
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "foundry"); data.setString("type", "foundry");
@ -171,24 +171,24 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
data.setFloat("base", 0.625F); data.setFloat("base", 0.625F);
data.setFloat("len", Math.max(1F, yCoord - (float) (Math.ceil(impact.yCoord) - 0.875))); data.setFloat("len", Math.max(1F, yCoord - (float) (Math.ceil(impact.yCoord) - 0.875)));
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord, zCoord + 0.5D + dir.offsetZ * 1.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord, zCoord + 0.5D + dir.offsetZ * 1.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50));
} }
PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 20F); PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 20F);
} }
/* pour recipe stack */ /* pour recipe stack */
if(!this.recipeStack.isEmpty()) { if(!this.recipeStack.isEmpty()) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
List<MaterialStack> toCast = new ArrayList(); List<MaterialStack> toCast = new ArrayList();
CrucibleRecipe recipe = this.getLoadedRecipe(); CrucibleRecipe recipe = this.getLoadedRecipe();
//if no recipe is loaded, everything from the recipe stack will be drainable //if no recipe is loaded, everything from the recipe stack will be drainable
if(recipe == null) { if(recipe == null) {
toCast.addAll(this.recipeStack); toCast.addAll(this.recipeStack);
} else { } else {
for(MaterialStack stack : this.recipeStack) { for(MaterialStack stack : this.recipeStack) {
for(MaterialStack output : recipe.output) { for(MaterialStack output : recipe.output) {
if(stack.material == output.material) { if(stack.material == output.material) {
@ -198,7 +198,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
} }
} }
} }
Vec3 impact = Vec3.createVectorHelper(0, 0, 0); Vec3 impact = Vec3.createVectorHelper(0, 0, 0);
MaterialStack didPour = CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord + 0.25D, zCoord + 0.5D + dir.offsetZ * 1.875D, 6, true, toCast, MaterialShapes.NUGGET.q(3), impact); MaterialStack didPour = CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord + 0.25D, zCoord + 0.5D + dir.offsetZ * 1.875D, 6, true, toCast, MaterialShapes.NUGGET.q(3), impact);
@ -211,7 +211,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
data.setFloat("base", 0.625F); data.setFloat("base", 0.625F);
data.setFloat("len", Math.max(1F, yCoord - (float) (Math.ceil(impact.yCoord) - 0.875))); data.setFloat("len", Math.max(1F, yCoord - (float) (Math.ceil(impact.yCoord) - 0.875)));
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord, zCoord + 0.5D + dir.offsetZ * 1.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord, zCoord + 0.5D + dir.offsetZ * 1.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50));
} }
PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 20F); PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 20F);
@ -220,51 +220,63 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
/* clean up stacks */ /* clean up stacks */
this.recipeStack.removeIf(o -> o.amount <= 0); this.recipeStack.removeIf(o -> o.amount <= 0);
this.wasteStack.removeIf(x -> x.amount <= 0); this.wasteStack.removeIf(x -> x.amount <= 0);
/* sync */ /* sync */
this.networkPackNT(25); this.networkPackNT(25);
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
buf.writeInt(progress); buf.writeInt(progress);
buf.writeInt(heat); buf.writeInt(heat);
buf.writeShort(recipeStack.size()); buf.writeShort(recipeStack.size());
for(MaterialStack sta : recipeStack) { for(MaterialStack sta : recipeStack) {
buf.writeInt(sta.material.id); if (sta.material == null)
buf.writeInt(-1);
else
buf.writeInt(sta.material.id);
buf.writeInt(sta.amount); buf.writeInt(sta.amount);
} }
buf.writeShort(wasteStack.size()); buf.writeShort(wasteStack.size());
for(MaterialStack sta : wasteStack) { for(MaterialStack sta : wasteStack) {
buf.writeInt(sta.material.id); if (sta.material == null)
buf.writeInt(-1);
else
buf.writeInt(sta.material.id);
buf.writeInt(sta.amount); buf.writeInt(sta.amount);
} }
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
progress = buf.readInt(); progress = buf.readInt();
heat = buf.readInt(); heat = buf.readInt();
recipeStack.clear(); recipeStack.clear();
wasteStack.clear(); wasteStack.clear();
int mats = buf.readShort(); int mats = buf.readShort();
for(int i = 0; i < mats; i++) { for(int i = 0; i < mats; i++) {
recipeStack.add(new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt())); int id = buf.readInt();
if (id == -1)
continue;
recipeStack.add(new MaterialStack(Mats.matById.get(id), buf.readInt()));
} }
mats = buf.readShort(); mats = buf.readShort();
for(int i = 0; i < mats; i++) { for(int i = 0; i < mats; i++) {
wasteStack.add(new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt())); int id = buf.readInt();
if (id == -1)
continue;
wasteStack.add(new MaterialStack(Mats.matById.get(id), buf.readInt()));
} }
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -273,20 +285,20 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
for(int i = 0; i < rec.length / 2; i++) { for(int i = 0; i < rec.length / 2; i++) {
recipeStack.add(new MaterialStack(Mats.matById.get(rec[i * 2]), rec[i * 2 + 1])); recipeStack.add(new MaterialStack(Mats.matById.get(rec[i * 2]), rec[i * 2 + 1]));
} }
int[] was = nbt.getIntArray("was"); int[] was = nbt.getIntArray("was");
for(int i = 0; i < was.length / 2; i++) { for(int i = 0; i < was.length / 2; i++) {
wasteStack.add(new MaterialStack(Mats.matById.get(was[i * 2]), was[i * 2 + 1])); wasteStack.add(new MaterialStack(Mats.matById.get(was[i * 2]), was[i * 2 + 1]));
} }
this.progress = nbt.getInteger("progress"); this.progress = nbt.getInteger("progress");
this.heat = nbt.getInteger("heat"); this.heat = nbt.getInteger("heat");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
int[] rec = new int[recipeStack.size() * 2]; int[] rec = new int[recipeStack.size() * 2];
int[] was = new int[wasteStack.size() * 2]; int[] was = new int[wasteStack.size() * 2];
for(int i = 0; i < recipeStack.size(); i++) { MaterialStack sta = recipeStack.get(i); rec[i * 2] = sta.material.id; rec[i * 2 + 1] = sta.amount; } for(int i = 0; i < recipeStack.size(); i++) { MaterialStack sta = recipeStack.get(i); rec[i * 2] = sta.material.id; rec[i * 2 + 1] = sta.amount; }
@ -296,21 +308,21 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
nbt.setInteger("progress", progress); nbt.setInteger("progress", progress);
nbt.setInteger("heat", heat); nbt.setInteger("heat", heat);
} }
protected void tryPullHeat() { protected void tryPullHeat() {
if(this.heat >= this.maxHeat) return; if(this.heat >= this.maxHeat) return;
TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord); TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
if(con instanceof IHeatSource) { if(con instanceof IHeatSource) {
IHeatSource source = (IHeatSource) con; IHeatSource source = (IHeatSource) con;
int diff = source.getHeatStored() - this.heat; int diff = source.getHeatStored() - this.heat;
if(diff == 0) { if(diff == 0) {
return; return;
} }
if(diff > 0) { if(diff > 0) {
diff = (int) Math.ceil(diff * diffusion); diff = (int) Math.ceil(diff * diffusion);
source.useUpHeat(diff); source.useUpHeat(diff);
@ -320,170 +332,170 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
return; return;
} }
} }
this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0); this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0);
} }
protected boolean trySmelt() { protected boolean trySmelt() {
if(this.heat < maxHeat / 2) return false; if(this.heat < maxHeat / 2) return false;
int slot = this.getFirstSmeltableSlot(); int slot = this.getFirstSmeltableSlot();
if(slot == -1) return false; if(slot == -1) return false;
int delta = this.heat - (maxHeat / 2); int delta = this.heat - (maxHeat / 2);
delta *= 0.05; delta *= 0.05;
this.progress += delta; this.progress += delta;
this.heat -= delta; this.heat -= delta;
if(this.progress >= processTime) { if(this.progress >= processTime) {
this.progress = 0; this.progress = 0;
List<MaterialStack> materials = Mats.getSmeltingMaterialsFromItem(slots[slot]); List<MaterialStack> materials = Mats.getSmeltingMaterialsFromItem(slots[slot]);
CrucibleRecipe recipe = getLoadedRecipe(); CrucibleRecipe recipe = getLoadedRecipe();
for(MaterialStack material : materials) { for(MaterialStack material : materials) {
boolean mainStack = recipe != null && (getQuantaFromType(recipe.input, material.material) > 0 || getQuantaFromType(recipe.output, material.material) > 0); boolean mainStack = recipe != null && (getQuantaFromType(recipe.input, material.material) > 0 || getQuantaFromType(recipe.output, material.material) > 0);
if(mainStack) { if(mainStack) {
this.addToStack(this.recipeStack, material); this.addToStack(this.recipeStack, material);
} else { } else {
this.addToStack(this.wasteStack, material); this.addToStack(this.wasteStack, material);
} }
} }
this.decrStackSize(slot, 1); this.decrStackSize(slot, 1);
} }
return true; return true;
} }
protected void tryRecipe() { protected void tryRecipe() {
CrucibleRecipe recipe = this.getLoadedRecipe(); CrucibleRecipe recipe = this.getLoadedRecipe();
if(recipe == null) return; if(recipe == null) return;
if(worldObj.getTotalWorldTime() % recipe.frequency > 0) return; if(worldObj.getTotalWorldTime() % recipe.frequency > 0) return;
for(MaterialStack stack : recipe.input) { for(MaterialStack stack : recipe.input) {
if(getQuantaFromType(this.recipeStack, stack.material) < stack.amount) return; if(getQuantaFromType(this.recipeStack, stack.material) < stack.amount) return;
} }
for(MaterialStack stack : this.recipeStack) { for(MaterialStack stack : this.recipeStack) {
stack.amount -= getQuantaFromType(recipe.input, stack.material); stack.amount -= getQuantaFromType(recipe.input, stack.material);
} }
outer: outer:
for(MaterialStack out : recipe.output) { for(MaterialStack out : recipe.output) {
for(MaterialStack stack : this.recipeStack) { for(MaterialStack stack : this.recipeStack) {
if(stack.material == out.material) { if(stack.material == out.material) {
stack.amount += out.amount; stack.amount += out.amount;
continue outer; continue outer;
} }
} }
this.recipeStack.add(out.copy()); this.recipeStack.add(out.copy());
} }
} }
protected int getFirstSmeltableSlot() { protected int getFirstSmeltableSlot() {
for(int i = 1; i < 10; i++) { for(int i = 1; i < 10; i++) {
ItemStack stack = slots[i]; ItemStack stack = slots[i];
if(stack != null && isItemSmeltable(stack)) { if(stack != null && isItemSmeltable(stack)) {
return i; return i;
} }
} }
return -1; return -1;
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack) { public boolean isItemValidForSlot(int i, ItemStack stack) {
if(i == 0) { if(i == 0) {
return stack.getItem() == ModItems.crucible_template; return stack.getItem() == ModItems.crucible_template;
} }
return isItemSmeltable(stack); return isItemSmeltable(stack);
} }
public boolean isItemSmeltable(ItemStack stack) { public boolean isItemSmeltable(ItemStack stack) {
List<MaterialStack> materials = Mats.getSmeltingMaterialsFromItem(stack); List<MaterialStack> materials = Mats.getSmeltingMaterialsFromItem(stack);
//if there's no materials in there at all, don't smelt //if there's no materials in there at all, don't smelt
if(materials.isEmpty()) if(materials.isEmpty())
return false; return false;
CrucibleRecipe recipe = getLoadedRecipe(); CrucibleRecipe recipe = getLoadedRecipe();
//needs to be true, will always be true if there's no recipe loaded //needs to be true, will always be true if there's no recipe loaded
boolean matchesRecipe = recipe == null; boolean matchesRecipe = recipe == null;
//the amount of material in the entire recipe input //the amount of material in the entire recipe input
int recipeContent = recipe != null ? recipe.getInputAmount() : 0; int recipeContent = recipe != null ? recipe.getInputAmount() : 0;
//the total amount of the current waste stack, used for simulation //the total amount of the current waste stack, used for simulation
int recipeAmount = getQuantaFromType(this.recipeStack, null); int recipeAmount = getQuantaFromType(this.recipeStack, null);
int wasteAmount = getQuantaFromType(this.wasteStack, null); int wasteAmount = getQuantaFromType(this.wasteStack, null);
for(MaterialStack mat : materials) { for(MaterialStack mat : materials) {
//if no recipe is loaded, everything will land in the waste stack //if no recipe is loaded, everything will land in the waste stack
int recipeInputRequired = recipe != null ? getQuantaFromType(recipe.input, mat.material) : 0; int recipeInputRequired = recipe != null ? getQuantaFromType(recipe.input, mat.material) : 0;
//this allows pouring the ouput material back into the crucible //this allows pouring the ouput material back into the crucible
if(recipe != null && getQuantaFromType(recipe.output, mat.material) > 0) { if(recipe != null && getQuantaFromType(recipe.output, mat.material) > 0) {
recipeAmount += mat.amount; recipeAmount += mat.amount;
matchesRecipe = true; matchesRecipe = true;
continue; continue;
} }
if(recipeInputRequired == 0) { if(recipeInputRequired == 0) {
//if this type isn't required by the recipe, add it to the waste stack //if this type isn't required by the recipe, add it to the waste stack
wasteAmount += mat.amount; wasteAmount += mat.amount;
} else { } else {
//the maximum is the recipe's ratio scaled up to the recipe stack's capacity //the maximum is the recipe's ratio scaled up to the recipe stack's capacity
int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent; int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent;
int amountStored = getQuantaFromType(recipeStack, mat.material); int amountStored = getQuantaFromType(recipeStack, mat.material);
matchesRecipe = true; matchesRecipe = true;
recipeAmount += mat.amount; recipeAmount += mat.amount;
//if the amount of that input would exceed the amount dictated by the recipe, return false //if the amount of that input would exceed the amount dictated by the recipe, return false
if(recipe != null && amountStored + mat.amount > matMaximum) if(recipe != null && amountStored + mat.amount > matMaximum)
return false; return false;
} }
} }
//if the amount doesn't exceed the capacity and the recipe matches (or isn't null), return true //if the amount doesn't exceed the capacity and the recipe matches (or isn't null), return true
return recipeAmount <= this.recipeZCapacity && wasteAmount <= this.wasteZCapacity && matchesRecipe; return recipeAmount <= this.recipeZCapacity && wasteAmount <= this.wasteZCapacity && matchesRecipe;
} }
public void addToStack(List<MaterialStack> stack, MaterialStack matStack) { public void addToStack(List<MaterialStack> stack, MaterialStack matStack) {
for(MaterialStack mat : stack) { for(MaterialStack mat : stack) {
if(mat.material == matStack.material) { if(mat.material == matStack.material) {
mat.amount += matStack.amount; mat.amount += matStack.amount;
return; return;
} }
} }
stack.add(matStack.copy()); stack.add(matStack.copy());
} }
public CrucibleRecipe getLoadedRecipe() { public CrucibleRecipe getLoadedRecipe() {
if(slots[0] != null && slots[0].getItem() == ModItems.crucible_template) { if(slots[0] != null && slots[0].getItem() == ModItems.crucible_template) {
return CrucibleRecipes.indexMapping.get(slots[0].getItemDamage()); return CrucibleRecipes.indexMapping.get(slots[0].getItemDamage());
} }
return null; return null;
} }
/* "Arrays and Lists don't have a common ancestor" my fucking ass */ /* "Arrays and Lists don't have a common ancestor" my fucking ass */
public int getQuantaFromType(MaterialStack[] stacks, NTMMaterial mat) { public int getQuantaFromType(MaterialStack[] stacks, NTMMaterial mat) {
for(MaterialStack stack : stacks) { for(MaterialStack stack : stacks) {
@ -493,7 +505,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
} }
return 0; return 0;
} }
public int getQuantaFromType(List<MaterialStack> stacks, NTMMaterial mat) { public int getQuantaFromType(List<MaterialStack> stacks, NTMMaterial mat) {
int sum = 0; int sum = 0;
for(MaterialStack stack : stacks) { for(MaterialStack stack : stacks) {
@ -522,12 +534,12 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUICrucible(player.inventory, this); return new GUICrucible(player.inventory, this);
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 1, xCoord - 1,
@ -538,10 +550,10 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
zCoord + 2 zCoord + 2
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -550,30 +562,30 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
@Override @Override
public boolean canAcceptPartialPour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) { public boolean canAcceptPartialPour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
CrucibleRecipe recipe = getLoadedRecipe(); CrucibleRecipe recipe = getLoadedRecipe();
if(recipe == null) { if(recipe == null) {
return getQuantaFromType(this.wasteStack, null) < this.wasteZCapacity; return getQuantaFromType(this.wasteStack, null) < this.wasteZCapacity;
} }
int recipeContent = recipe.getInputAmount(); int recipeContent = recipe.getInputAmount();
int recipeInputRequired = getQuantaFromType(recipe.input, stack.material); int recipeInputRequired = getQuantaFromType(recipe.input, stack.material);
int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent; int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent;
int amountStored = getQuantaFromType(recipeStack, stack.material); int amountStored = getQuantaFromType(recipeStack, stack.material);
return amountStored < matMaximum && getQuantaFromType(this.recipeStack, null) < this.recipeZCapacity; return amountStored < matMaximum && getQuantaFromType(this.recipeStack, null) < this.recipeZCapacity;
} }
@Override @Override
public MaterialStack pour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) { public MaterialStack pour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
CrucibleRecipe recipe = getLoadedRecipe(); CrucibleRecipe recipe = getLoadedRecipe();
if(recipe == null) { if(recipe == null) {
int amount = getQuantaFromType(this.wasteStack, null); int amount = getQuantaFromType(this.wasteStack, null);
if(amount + stack.amount <= this.wasteZCapacity) { if(amount + stack.amount <= this.wasteZCapacity) {
this.addToStack(this.wasteStack, stack.copy()); this.addToStack(this.wasteStack, stack.copy());
return null; return null;
@ -583,16 +595,16 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
return new MaterialStack(stack.material, stack.amount - toAdd); return new MaterialStack(stack.material, stack.amount - toAdd);
} }
} }
int recipeContent = recipe.getInputAmount(); int recipeContent = recipe.getInputAmount();
int recipeInputRequired = getQuantaFromType(recipe.input, stack.material); int recipeInputRequired = getQuantaFromType(recipe.input, stack.material);
int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent; int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent;
if(recipeInputRequired + stack.amount <= matMaximum) { if(recipeInputRequired + stack.amount <= matMaximum) {
this.addToStack(this.recipeStack, stack.copy()); this.addToStack(this.recipeStack, stack.copy());
return null; return null;
} }
int toAdd = matMaximum - stack.amount; int toAdd = matMaximum - stack.amount;
toAdd = Math.min(toAdd, this.recipeZCapacity - getQuantaFromType(this.recipeStack, null)); toAdd = Math.min(toAdd, this.recipeZCapacity - getQuantaFromType(this.recipeStack, null));
this.addToStack(this.recipeStack, new MaterialStack(stack.material, toAdd)); this.addToStack(this.recipeStack, new MaterialStack(stack.material, toAdd));

View File

@ -35,16 +35,16 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineRadiolysis extends TileEntityMachineBase implements IEnergyProviderMK2, IFluidStandardTransceiver, IGUIProvider, IInfoProviderEC, IFluidCopiable { public class TileEntityMachineRadiolysis extends TileEntityMachineBase implements IEnergyProviderMK2, IFluidStandardTransceiver, IGUIProvider, IInfoProviderEC, IFluidCopiable {
public long power; public long power;
public static final int maxPower = 1000000; public static final int maxPower = 1000000;
public int heat; public int heat;
public FluidTank[] tanks; public FluidTank[] tanks;
private static final int[] slot_io = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13 }; private static final int[] slot_io = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13 };
private static final int[] slot_rtg = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; private static final int[] slot_rtg = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
public TileEntityMachineRadiolysis() { public TileEntityMachineRadiolysis() {
super(15); //10 rtg slots, 2 fluid ID slots (io), 2 irradiation slots (io), battery slot super(15); //10 rtg slots, 2 fluid ID slots (io), 2 irradiation slots (io), battery slot
tanks = new FluidTank[3]; tanks = new FluidTank[3];
@ -52,12 +52,12 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
tanks[1] = new FluidTank(Fluids.NONE, 2_000); tanks[1] = new FluidTank(Fluids.NONE, 2_000);
tanks[2] = new FluidTank(Fluids.NONE, 2_000); tanks[2] = new FluidTank(Fluids.NONE, 2_000);
} }
@Override @Override
public String getName() { public String getName() {
return "container.radiolysis"; return "container.radiolysis";
} }
/* IO Methods */ /* IO Methods */
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) { public boolean isItemValidForSlot(int i, ItemStack itemStack) {
@ -68,32 +68,32 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
public int[] getAccessibleSlotsFromSide(int side) { public int[] getAccessibleSlotsFromSide(int side) {
return slot_io; return slot_io;
} }
@Override @Override
public boolean canExtractItem(int i, ItemStack itemStack, int j) { public boolean canExtractItem(int i, ItemStack itemStack, int j) {
return (i < 10 && itemStack.getItem() instanceof ItemRTGPelletDepleted) || i == 13; return (i < 10 && itemStack.getItem() instanceof ItemRTGPelletDepleted) || i == 13;
} }
/* NBT Methods */ /* NBT Methods */
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.heat = nbt.getInteger("heat"); this.heat = nbt.getInteger("heat");
tanks[0].readFromNBT(nbt, "input"); tanks[0].readFromNBT(nbt, "input");
tanks[1].readFromNBT(nbt, "output1"); tanks[1].readFromNBT(nbt, "output1");
tanks[2].readFromNBT(nbt, "output2"); tanks[2].readFromNBT(nbt, "output2");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("power", power); nbt.setLong("power", power);
nbt.setInteger("heat", heat); nbt.setInteger("heat", heat);
tanks[0].writeToNBT(nbt, "input"); tanks[0].writeToNBT(nbt, "input");
tanks[1].writeToNBT(nbt, "output1"); tanks[1].writeToNBT(nbt, "output1");
tanks[2].writeToNBT(nbt, "output2"); tanks[2].writeToNBT(nbt, "output2");
@ -101,29 +101,29 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
power = Library.chargeItemsFromTE(slots, 14, power, maxPower); power = Library.chargeItemsFromTE(slots, 14, power, maxPower);
heat = RTGUtil.updateRTGs(slots, slot_rtg); heat = RTGUtil.updateRTGs(slots, slot_rtg);
power += heat * 10; power += heat * 10;
if(power > maxPower) if(power > maxPower)
power = maxPower; power = maxPower;
tanks[0].setType(10, 11, slots); tanks[0].setType(10, 11, slots);
setupTanks(); setupTanks();
if(heat > 100) { if(heat > 100) {
int crackTime = (int) Math.max(-0.1 * (heat - 100) + 30, 5); int crackTime = (int) Math.max(-0.1 * (heat - 100) + 30, 5);
if(worldObj.getTotalWorldTime() % crackTime == 0) if(worldObj.getTotalWorldTime() % crackTime == 0)
crack(); crack();
if(heat >= 200 && worldObj.getTotalWorldTime() % 100 == 0) if(heat >= 200 && worldObj.getTotalWorldTime() % 100 == 0)
sterilize(); sterilize();
} }
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.tryProvide(worldObj, pos.getX(), pos.getY(),pos.getZ(), pos.getDir()); this.tryProvide(worldObj, pos.getX(), pos.getY(),pos.getZ(), pos.getDir());
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(),pos.getZ(), pos.getDir()); this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(),pos.getZ(), pos.getDir());
@ -150,9 +150,9 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
super.deserialize(buf); super.deserialize(buf);
this.power = buf.readLong(); this.power = buf.readLong();
this.heat = buf.readInt(); this.heat = buf.readInt();
tanks[0].serialize(buf); tanks[0].deserialize(buf);
tanks[1].serialize(buf); tanks[1].deserialize(buf);
tanks[2].serialize(buf); tanks[2].deserialize(buf);
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
@ -163,17 +163,17 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
new DirPos(xCoord, yCoord, zCoord - 2, Library.NEG_Z) new DirPos(xCoord, yCoord, zCoord - 2, Library.NEG_Z)
}; };
} }
/* Processing Methods */ /* Processing Methods */
private void crack() { private void crack() {
Pair<FluidStack, FluidStack> quart = RadiolysisRecipes.getRadiolysis(tanks[0].getTankType()); Pair<FluidStack, FluidStack> quart = RadiolysisRecipes.getRadiolysis(tanks[0].getTankType());
if(quart != null) { if(quart != null) {
int left = quart.getKey().fill; int left = quart.getKey().fill;
int right = quart.getValue().fill; int right = quart.getValue().fill;
if(tanks[0].getFill() >= 100 && hasSpace(left, right)) { if(tanks[0].getFill() >= 100 && hasSpace(left, right)) {
tanks[0].setFill(tanks[0].getFill() - 100); tanks[0].setFill(tanks[0].getFill() - 100);
tanks[1].setFill(tanks[1].getFill() + left); tanks[1].setFill(tanks[1].getFill() + left);
@ -181,15 +181,15 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
} }
} }
} }
private boolean hasSpace(int left, int right) { private boolean hasSpace(int left, int right) {
return tanks[1].getFill() + left <= tanks[1].getMaxFill() && tanks[2].getFill() + right <= tanks[2].getMaxFill(); return tanks[1].getFill() + left <= tanks[1].getMaxFill() && tanks[2].getFill() + right <= tanks[2].getMaxFill();
} }
private void setupTanks() { private void setupTanks() {
Pair<FluidStack, FluidStack> quart = RadiolysisRecipes.getRadiolysis(tanks[0].getTankType()); Pair<FluidStack, FluidStack> quart = RadiolysisRecipes.getRadiolysis(tanks[0].getTankType());
if(quart != null) { if(quart != null) {
tanks[1].setTankType(quart.getKey().type); tanks[1].setTankType(quart.getKey().type);
tanks[2].setTankType(quart.getValue().type); tanks[2].setTankType(quart.getValue().type);
@ -198,21 +198,21 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
tanks[1].setTankType(Fluids.NONE); tanks[1].setTankType(Fluids.NONE);
tanks[2].setTankType(Fluids.NONE); tanks[2].setTankType(Fluids.NONE);
} }
} }
// Code: pressure, sword, sterilize. // Code: pressure, sword, sterilize.
private void sterilize() { private void sterilize() {
if(slots[12] != null) { if(slots[12] != null) {
if(slots[12].getItem() instanceof ItemFood && !(slots[12].getItem() == ModItems.pancake)) { if(slots[12].getItem() instanceof ItemFood && !(slots[12].getItem() == ModItems.pancake)) {
this.decrStackSize(12, 1); this.decrStackSize(12, 1);
} }
if(!checkIfValid()) return; if(!checkIfValid()) return;
ItemStack output = slots[12].copy(); ItemStack output = slots[12].copy();
output.stackSize = 1; output.stackSize = 1;
if(slots[13] == null) { if(slots[13] == null) {
this.decrStackSize(12, output.stackSize); this.decrStackSize(12, output.stackSize);
slots[13] = output; slots[13] = output;
@ -232,14 +232,14 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
} }
} }
} }
private boolean checkIfValid() { private boolean checkIfValid() {
if(slots[12] == null) return false; if(slots[12] == null) return false;
if(!slots[12].hasTagCompound()) return false; if(!slots[12].hasTagCompound()) return false;
if(!slots[12].getTagCompound().getBoolean("ntmContagion")) return false; if(!slots[12].getTagCompound().getBoolean("ntmContagion")) return false;
return true; return true;
} }
/* Power methods */ /* Power methods */
@Override @Override
public void setPower(long power) { public void setPower(long power) {
@ -255,7 +255,7 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
public long getMaxPower() { public long getMaxPower() {
return maxPower; return maxPower;
} }
@Override @Override
public FluidTank[] getAllTanks() { public FluidTank[] getAllTanks() {
return tanks; return tanks;
@ -275,11 +275,11 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
public boolean canConnect(FluidType type, ForgeDirection dir) { public boolean canConnect(FluidType type, ForgeDirection dir) {
return dir != ForgeDirection.UNKNOWN && dir != ForgeDirection.DOWN; return dir != ForgeDirection.UNKNOWN && dir != ForgeDirection.DOWN;
} }
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord, zCoord - 1, xCoord + 2, yCoord + 3, zCoord + 2); return AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord, zCoord - 1, xCoord + 2, yCoord + 3, zCoord + 2);
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
return 65536.0D; return 65536.0D;

View File

@ -81,7 +81,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
if(canProcess()) { if(canProcess()) {
int minAmount = mold.getCost() * 9; int minAmount = mold.getCost() * 9;
// Makes it flush the buffers after 10 seconds of inactivity // Makes it flush the buffers after 10 seconds of inactivity
if(worldObj.getWorldTime() >= lastCastTick + 200) { if(worldObj.getWorldTime() >= lastCastTick + 200) {
minAmount = mold.getCost(); minAmount = mold.getCost();
@ -116,9 +116,10 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
lastCastTick = worldObj.getWorldTime(); lastCastTick = worldObj.getWorldTime();
} }
} }
}
sendStandard(150); sendStandard(150);
}
} }
@ -190,7 +191,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
} }
return false; return false;
} }
@Override @Override
public boolean standardCheck(World world, int x, int y, int z, ForgeDirection side, Mats.MaterialStack stack) { public boolean standardCheck(World world, int x, int y, int z, ForgeDirection side, Mats.MaterialStack stack) {
@ -257,12 +258,14 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
return new GUIMachineStrandCaster(player.inventory, this); return new GUIMachineStrandCaster(player.inventory, this);
} }
@Override public void serialize(ByteBuf buf) { @Override
public void serialize(ByteBuf buf) {
water.serialize(buf); water.serialize(buf);
steam.serialize(buf); steam.serialize(buf);
} }
@Override public void deserialize(ByteBuf buf) { @Override
public void deserialize(ByteBuf buf) {
water.deserialize(buf); water.deserialize(buf);
steam.deserialize(buf); steam.deserialize(buf);
} }
@ -341,7 +344,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
} }
public boolean isLoaded = true; public boolean isLoaded = true;
@Override @Override
public boolean isLoaded() { public boolean isLoaded() {
return isLoaded; return isLoaded;

View File

@ -100,7 +100,7 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.fluidUsed = 0; this.fluidUsed = 0;
this.output = 0; this.output = 0;
@ -111,63 +111,63 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
tank.setType(3, slots); tank.setType(3, slots);
tank.loadTank(1, 2, slots); tank.loadTank(1, 2, slots);
int maxVent = 50; int maxVent = 50;
int maxBurn = 10; int maxBurn = 10;
if(isOn && tank.getFill() > 0) { if(isOn && tank.getFill() > 0) {
UpgradeManager.eval(slots, 4, 5); UpgradeManager.eval(slots, 4, 5);
int burn = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int burn = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
int yield = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3); int yield = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
maxVent += maxVent * burn; maxVent += maxVent * burn;
maxBurn += maxBurn * burn; maxBurn += maxBurn * burn;
if(!doesBurn || !(tank.getTankType().hasTrait(FT_Flammable.class))) { if(!doesBurn || !(tank.getTankType().hasTrait(FT_Flammable.class))) {
if(tank.getTankType().hasTrait(FT_Gaseous.class) || tank.getTankType().hasTrait(FT_Gaseous_ART.class)) { if(tank.getTankType().hasTrait(FT_Gaseous.class) || tank.getTankType().hasTrait(FT_Gaseous_ART.class)) {
int eject = Math.min(maxVent, tank.getFill()); int eject = Math.min(maxVent, tank.getFill());
this.fluidUsed = eject; this.fluidUsed = eject;
tank.setFill(tank.getFill() - eject); tank.setFill(tank.getFill() - eject);
tank.getTankType().onFluidRelease(this, tank, eject); tank.getTankType().onFluidRelease(this, tank, eject);
if(worldObj.getTotalWorldTime() % 7 == 0) if(worldObj.getTotalWorldTime() % 7 == 0)
this.worldObj.playSoundEffect(this.xCoord, this.yCoord + 11, this.zCoord, "random.fizz", getVolume(1.5F), 0.5F); this.worldObj.playSoundEffect(this.xCoord, this.yCoord + 11, this.zCoord, "random.fizz", getVolume(1.5F), 0.5F);
if(worldObj.getTotalWorldTime() % 5 == 0 && eject > 0) { if(worldObj.getTotalWorldTime() % 5 == 0 && eject > 0) {
FT_Polluting.pollute(worldObj, xCoord, yCoord, zCoord, tank.getTankType(), FluidReleaseType.SPILL, eject * 5); FT_Polluting.pollute(worldObj, xCoord, yCoord, zCoord, tank.getTankType(), FluidReleaseType.SPILL, eject * 5);
} }
} }
} else { } else {
if(tank.getTankType().hasTrait(FT_Flammable.class)) { if(tank.getTankType().hasTrait(FT_Flammable.class)) {
int eject = Math.min(maxBurn, tank.getFill()); int eject = Math.min(maxBurn, tank.getFill());
this.fluidUsed = eject; this.fluidUsed = eject;
tank.setFill(tank.getFill() - eject); tank.setFill(tank.getFill() - eject);
int penalty = 5; int penalty = 5;
if(!tank.getTankType().hasTrait(FT_Gaseous.class) && !tank.getTankType().hasTrait(FT_Gaseous_ART.class)) if(!tank.getTankType().hasTrait(FT_Gaseous.class) && !tank.getTankType().hasTrait(FT_Gaseous_ART.class))
penalty = 10; penalty = 10;
long powerProd = tank.getTankType().getTrait(FT_Flammable.class).getHeatEnergy() * eject / 1_000; // divided by 1000 per mB long powerProd = tank.getTankType().getTrait(FT_Flammable.class).getHeatEnergy() * eject / 1_000; // divided by 1000 per mB
powerProd /= penalty; powerProd /= penalty;
powerProd += powerProd * yield / 3; powerProd += powerProd * yield / 3;
this.output = (int) powerProd; this.output = (int) powerProd;
power += powerProd; power += powerProd;
if(power > maxPower) if(power > maxPower)
power = maxPower; power = maxPower;
ParticleUtil.spawnGasFlame(worldObj, this.xCoord + 0.5F, this.yCoord + 11.75F, this.zCoord + 0.5F, worldObj.rand.nextGaussian() * 0.15, 0.2, worldObj.rand.nextGaussian() * 0.15); ParticleUtil.spawnGasFlame(worldObj, this.xCoord + 0.5F, this.yCoord + 11.75F, this.zCoord + 0.5F, worldObj.rand.nextGaussian() * 0.15, 0.2, worldObj.rand.nextGaussian() * 0.15);
List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord + 12, zCoord - 2, xCoord + 2, yCoord + 17, zCoord + 2)); List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord + 12, zCoord - 2, xCoord + 2, yCoord + 17, zCoord + 2));
for(Entity e : list) { for(Entity e : list) {
e.setFire(5); e.setFire(5);
e.attackEntityFrom(DamageSource.onFire, 5F); e.attackEntityFrom(DamageSource.onFire, 5F);
} }
if(worldObj.getTotalWorldTime() % 3 == 0) if(worldObj.getTotalWorldTime() % 3 == 0)
this.worldObj.playSoundEffect(this.xCoord, this.yCoord + 11, this.zCoord, "hbm:weapon.flamethrowerShoot", getVolume(1.5F), 0.75F); this.worldObj.playSoundEffect(this.xCoord, this.yCoord + 11, this.zCoord, "hbm:weapon.flamethrowerShoot", getVolume(1.5F), 0.75F);
@ -183,11 +183,11 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
if(isOn && tank.getFill() > 0) { if(isOn && tank.getFill() > 0) {
if((!doesBurn || !(tank.getTankType().hasTrait(FT_Flammable.class))) && (tank.getTankType().hasTrait(FT_Gaseous.class) || tank.getTankType().hasTrait(FT_Gaseous_ART.class))) { if((!doesBurn || !(tank.getTankType().hasTrait(FT_Flammable.class))) && (tank.getTankType().hasTrait(FT_Gaseous.class) || tank.getTankType().hasTrait(FT_Gaseous_ART.class))) {
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "tower"); data.setString("type", "tower");
data.setFloat("lift", 1F); data.setFloat("lift", 1F);
@ -199,13 +199,13 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
data.setDouble("posX", xCoord + 0.5); data.setDouble("posX", xCoord + 0.5);
data.setDouble("posZ", zCoord + 0.5); data.setDouble("posZ", zCoord + 0.5);
data.setDouble("posY", yCoord + 11); data.setDouble("posY", yCoord + 11);
MainRegistry.proxy.effectNT(data); MainRegistry.proxy.effectNT(data);
} }
if(doesBurn && tank.getTankType().hasTrait(FT_Flammable.class) && MainRegistry.proxy.me().getDistanceSq(xCoord, yCoord + 10, zCoord) <= 1024) { if(doesBurn && tank.getTankType().hasTrait(FT_Flammable.class) && MainRegistry.proxy.me().getDistanceSq(xCoord, yCoord + 10, zCoord) <= 1024) {
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaExt"); data.setString("type", "vanillaExt");
data.setString("mode", "smoke"); data.setString("mode", "smoke");
@ -221,13 +221,13 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
data.setDouble("posZ", zCoord - 0.5); data.setDouble("posZ", zCoord - 0.5);
data.setDouble("posY", yCoord + 11.75); data.setDouble("posY", yCoord + 11.75);
} }
MainRegistry.proxy.effectNT(data); MainRegistry.proxy.effectNT(data);
} }
} }
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + 2, yCoord, zCoord, Library.POS_X), new DirPos(xCoord + 2, yCoord, zCoord, Library.POS_X),
@ -252,7 +252,7 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
this.power = buf.readLong(); this.power = buf.readLong();
this.isOn = buf.readBoolean(); this.isOn = buf.readBoolean();
this.doesBurn = buf.readBoolean(); this.doesBurn = buf.readBoolean();
tank.serialize(buf); tank.deserialize(buf);
} }
@Override @Override

View File

@ -18,18 +18,18 @@ import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPacketReceiver, IControlReceiverFilter { public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPacketReceiver, IControlReceiverFilter {
private int stack = 0; private int stack = 0;
public boolean output = false; public boolean output = false;
private int capacity; private int capacity;
public int redstone = 0; public int redstone = 0;
@SideOnly(Side.CLIENT) public ItemStack type; @SideOnly(Side.CLIENT) public ItemStack type;
public TileEntityMassStorage() { public TileEntityMassStorage() {
super(3); super(3);
} }
public TileEntityMassStorage(int capacity) { public TileEntityMassStorage(int capacity) {
this(); this();
this.capacity = capacity; this.capacity = capacity;
@ -39,43 +39,43 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
public String getInventoryName() { public String getInventoryName() {
return "container.massStorage"; return "container.massStorage";
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
int newRed = this.getStockpile() * 15 / this.capacity; int newRed = this.getStockpile() * 15 / this.capacity;
if(newRed != this.redstone) { if(newRed != this.redstone) {
this.redstone = newRed; this.redstone = newRed;
this.markDirty(); this.markDirty();
} }
if(slots[0] != null && slots[0].getItem() == ModItems.fluid_barrel_infinite) { if(slots[0] != null && slots[0].getItem() == ModItems.fluid_barrel_infinite) {
this.stack = this.getCapacity(); this.stack = this.getCapacity();
} }
if(this.getType() == null) if(this.getType() == null)
this.stack = 0; this.stack = 0;
if(getType() != null && getStockpile() < getCapacity() && slots[0] != null && slots[0].isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(slots[0], getType())) { if(getType() != null && getStockpile() < getCapacity() && slots[0] != null && slots[0].isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(slots[0], getType())) {
int remaining = getCapacity() - getStockpile(); int remaining = getCapacity() - getStockpile();
int toRemove = Math.min(remaining, slots[0].stackSize); int toRemove = Math.min(remaining, slots[0].stackSize);
this.decrStackSize(0, toRemove); this.decrStackSize(0, toRemove);
this.stack += toRemove; this.stack += toRemove;
this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this); this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
} }
if(output && getType() != null) { if(output && getType() != null) {
if(slots[2] != null && !(slots[2].isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(slots[2], getType()))) { if(slots[2] != null && !(slots[2].isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(slots[2], getType()))) {
return; return;
} }
int amount = Math.min(getStockpile(), getType().getMaxStackSize()); int amount = Math.min(getStockpile(), getType().getMaxStackSize());
if(amount > 0) { if(amount > 0) {
if(slots[2] == null) { if(slots[2] == null) {
slots[2] = slots[1].copy(); slots[2] = slots[1].copy();
@ -96,7 +96,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
buf.writeInt(this.stack); buf.writeInt(this.stack);
buf.writeBoolean(this.output); buf.writeBoolean(this.output);
BufferUtil.writeItemStack(buf, this.type); BufferUtil.writeItemStack(buf, this.slots[1]);
} }
@Override @Override
@ -105,19 +105,19 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
this.output = buf.readBoolean(); this.output = buf.readBoolean();
this.type = BufferUtil.readItemStack(buf); this.type = BufferUtil.readItemStack(buf);
} }
public int getCapacity() { public int getCapacity() {
return capacity; return capacity;
} }
public ItemStack getType() { public ItemStack getType() {
return slots[1] == null ? null : slots[1].copy(); return slots[1] == null ? null : slots[1].copy();
} }
public int getStockpile() { public int getStockpile() {
return stack; return stack;
} }
public void setStockpile(int stack) { public void setStockpile(int stack) {
this.stack = stack; this.stack = stack;
} }
@ -144,7 +144,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
this.output = nbt.getBoolean("output"); this.output = nbt.getBoolean("output");
this.capacity = nbt.getInteger("capacity"); this.capacity = nbt.getInteger("capacity");
this.redstone = nbt.getByte("redstone"); this.redstone = nbt.getByte("redstone");
if(this.capacity <= 0) { if(this.capacity <= 0) {
this.capacity = 10_000; this.capacity = 10_000;
} }
@ -166,20 +166,20 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
@Override @Override
public void receiveControl(NBTTagCompound data) { public void receiveControl(NBTTagCompound data) {
if(data.hasKey("provide") && slots[1] != null) { if(data.hasKey("provide") && slots[1] != null) {
if(this.getStockpile() == 0) { if(this.getStockpile() == 0) {
return; return;
} }
int amount = data.getBoolean("provide") ? slots[1].getMaxStackSize() : 1; int amount = data.getBoolean("provide") ? slots[1].getMaxStackSize() : 1;
amount = Math.min(amount, getStockpile()); amount = Math.min(amount, getStockpile());
if(slots[2] != null && !(slots[2].isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(slots[2], getType()))) { if(slots[2] != null && !(slots[2].isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(slots[2], getType()))) {
return; return;
} }
if(slots[2] == null) { if(slots[2] == null) {
slots[2] = slots[1].copy(); slots[2] = slots[1].copy();
slots[2].stackSize = amount; slots[2].stackSize = amount;
@ -189,7 +189,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
} }
this.stack -= amount; this.stack -= amount;
} }
if(data.hasKey("toggle")) { if(data.hasKey("toggle")) {
this.output = !output; this.output = !output;
} }

View File

@ -26,6 +26,7 @@ import com.hbm.packet.toclient.AuxParticlePacketNT;
import com.hbm.particle.SpentCasing; import com.hbm.particle.SpentCasing;
import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.BufferUtil;
import com.hbm.util.CompatExternal; import com.hbm.util.CompatExternal;
import api.hbm.energymk2.IEnergyReceiverMK2; import api.hbm.energymk2.IEnergyReceiverMK2;
@ -75,10 +76,10 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
@Override @Override
public void receiveControl(NBTTagCompound data) { public void receiveControl(NBTTagCompound data) {
if(data.hasKey("del")) { if(data.hasKey("del")) {
this.removeName(data.getInteger("del")); this.removeName(data.getInteger("del"));
} else if(data.hasKey("name")) { } else if(data.hasKey("name")) {
this.addName(data.getString("name")); this.addName(data.getString("name"));
} }
@ -101,7 +102,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public boolean aligned = false; public boolean aligned = false;
//how many ticks until the next check //how many ticks until the next check
public int searchTimer; public int searchTimer;
public long power; public long power;
public boolean targetPlayers = false; public boolean targetPlayers = false;
@ -111,32 +112,32 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public Entity target; public Entity target;
public Vec3 tPos; public Vec3 tPos;
//tally marks! //tally marks!
public int stattrak; public int stattrak;
public int casingDelay; public int casingDelay;
protected SpentCasing cachedCasingConfig = null; protected SpentCasing cachedCasingConfig = null;
/** /**
* X * X
* *
* YYY * YYY
* YYY * YYY
* YYY Z * YYY Z
* *
* X -> ai slot (0) * X -> ai slot (0)
* Y -> ammo slots (1 - 9) * Y -> ammo slots (1 - 9)
* Z -> battery slot (10) * Z -> battery slot (10)
*/ */
public TileEntityTurretBaseNT() { public TileEntityTurretBaseNT() {
super(11); super(11);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.isOn = nbt.getBoolean("isOn"); this.isOn = nbt.getBoolean("isOn");
this.targetPlayers = nbt.getBoolean("targetPlayers"); this.targetPlayers = nbt.getBoolean("targetPlayers");
@ -145,11 +146,11 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
this.targetMachines = nbt.getBoolean("targetMachines"); this.targetMachines = nbt.getBoolean("targetMachines");
this.stattrak = nbt.getInteger("stattrak"); this.stattrak = nbt.getInteger("stattrak");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("power", this.power); nbt.setLong("power", this.power);
nbt.setBoolean("isOn", this.isOn); nbt.setBoolean("isOn", this.isOn);
nbt.setBoolean("targetPlayers", this.targetPlayers); nbt.setBoolean("targetPlayers", this.targetPlayers);
@ -158,80 +159,80 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
nbt.setBoolean("targetMachines", this.targetMachines); nbt.setBoolean("targetMachines", this.targetMachines);
nbt.setInteger("stattrak", this.stattrak); nbt.setInteger("stattrak", this.stattrak);
} }
public void manualSetup() { } public void manualSetup() { }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(worldObj.isRemote) { if(worldObj.isRemote) {
this.lastRotationPitch = this.rotationPitch; this.lastRotationPitch = this.rotationPitch;
this.lastRotationYaw = this.rotationYaw; this.lastRotationYaw = this.rotationYaw;
this.rotationPitch = this.syncRotationPitch; this.rotationPitch = this.syncRotationPitch;
this.rotationYaw = this.syncRotationYaw; this.rotationYaw = this.syncRotationYaw;
} }
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.aligned = false; this.aligned = false;
this.updateConnections(); this.updateConnections();
if(this.target != null && !target.isEntityAlive()) { if(this.target != null && !target.isEntityAlive()) {
this.target = null; this.target = null;
this.stattrak++; this.stattrak++;
} }
if(target != null) { if(target != null) {
if(!this.entityInLOS(this.target)) { if(!this.entityInLOS(this.target)) {
this.target = null; this.target = null;
} }
} }
if(target != null) { if(target != null) {
this.tPos = this.getEntityPos(target); this.tPos = this.getEntityPos(target);
} else { } else {
this.tPos = null; this.tPos = null;
} }
if(isOn() && hasPower()) { if(isOn() && hasPower()) {
if(tPos != null) if(tPos != null)
this.alignTurret(); this.alignTurret();
} else { } else {
this.target = null; this.target = null;
this.tPos = null; this.tPos = null;
} }
if(this.target != null && !target.isEntityAlive()) { if(this.target != null && !target.isEntityAlive()) {
this.target = null; this.target = null;
this.tPos = null; this.tPos = null;
this.stattrak++; this.stattrak++;
} }
if(isOn() && hasPower()) { if(isOn() && hasPower()) {
searchTimer--; searchTimer--;
this.setPower(this.getPower() - this.getConsumption()); this.setPower(this.getPower() - this.getConsumption());
if(searchTimer <= 0) { if(searchTimer <= 0) {
searchTimer = this.getDecetorInterval(); searchTimer = this.getDecetorInterval();
if(this.target == null) if(this.target == null)
this.seekNewTarget(); this.seekNewTarget();
} }
} else { } else {
searchTimer = 0; searchTimer = 0;
} }
if(this.aligned) { if(this.aligned) {
this.updateFiringTick(); this.updateFiringTick();
} }
this.power = Library.chargeTEFromItems(slots, 10, this.power, this.getMaxPower()); this.power = Library.chargeTEFromItems(slots, 10, this.power, this.getMaxPower());
this.networkPackNT(250); this.networkPackNT(250);
if(usesCasings() && this.casingDelay() > 0) { if(usesCasings() && this.casingDelay() > 0) {
if(casingDelay > 0) { if(casingDelay > 0) {
casingDelay--; casingDelay--;
@ -239,12 +240,12 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
spawnCasing(); spawnCasing();
} }
} }
} else { } else {
//this will fix the interpolation error when the turret crosses the 360° point //this will fix the interpolation error when the turret crosses the 360° point
if(Math.abs(this.lastRotationYaw - this.rotationYaw) > Math.PI) { if(Math.abs(this.lastRotationYaw - this.rotationYaw) > Math.PI) {
if(this.lastRotationYaw < this.rotationYaw) if(this.lastRotationYaw < this.rotationYaw)
this.lastRotationYaw += Math.PI * 2; this.lastRotationYaw += Math.PI * 2;
else else
@ -256,12 +257,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
buf.writeBoolean(this.tPos != null); BufferUtil.writeVec3(buf, this.tPos);
if(this.tPos != null) {
buf.writeDouble(this.tPos.xCoord);
buf.writeDouble(this.tPos.yCoord);
buf.writeDouble(this.tPos.zCoord);
}
buf.writeDouble(this.rotationPitch); buf.writeDouble(this.rotationPitch);
buf.writeDouble(this.rotationYaw); buf.writeDouble(this.rotationYaw);
buf.writeLong(this.power); buf.writeLong(this.power);
@ -276,12 +272,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
boolean hasTPos = buf.readBoolean(); this.tPos = BufferUtil.readVec3(buf);
if(hasTPos) {
this.tPos.xCoord = buf.readDouble();
this.tPos.yCoord = buf.readDouble();
this.tPos.zCoord = buf.readDouble();
}
this.rotationPitch = buf.readDouble(); this.rotationPitch = buf.readDouble();
this.rotationYaw = buf.readDouble(); this.rotationYaw = buf.readDouble();
this.power = buf.readLong(); this.power = buf.readLong();
@ -292,7 +283,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
this.targetMachines = buf.readBoolean(); this.targetMachines = buf.readBoolean();
this.stattrak = buf.readInt(); this.stattrak = buf.readInt();
} }
protected void updateConnections() { protected void updateConnections() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
@ -313,7 +304,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
@Override @Override
public void handleButtonPacket(int value, int meta) { public void handleButtonPacket(int value, int meta) {
switch(meta) { switch(meta) {
case 0:this.isOn = !this.isOn; break; case 0:this.isOn = !this.isOn; break;
case 1:this.targetPlayers = !this.targetPlayers; break; case 1:this.targetPlayers = !this.targetPlayers; break;
@ -322,51 +313,51 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
case 4:this.targetMachines = !this.targetMachines; break; case 4:this.targetMachines = !this.targetMachines; break;
} }
} }
public abstract void updateFiringTick(); public abstract void updateFiringTick();
public boolean usesCasings() { return false; } public boolean usesCasings() { return false; }
public int casingDelay() { return 0; } public int casingDelay() { return 0; }
public BulletConfiguration getFirstConfigLoaded() { public BulletConfiguration getFirstConfigLoaded() {
List<Integer> list = getAmmoList(); List<Integer> list = getAmmoList();
if(list == null || list.isEmpty()) if(list == null || list.isEmpty())
return null; return null;
//doing it like this will fire slots in the right order, not in the order of the configs //doing it like this will fire slots in the right order, not in the order of the configs
//you know, the weird thing the IItemGunBase does //you know, the weird thing the IItemGunBase does
for(int i = 1; i < 10; i++) { for(int i = 1; i < 10; i++) {
if(slots[i] != null) { if(slots[i] != null) {
for(Integer c : list) { //we can afford all this extra iteration trash on the count that a turret has at most like 4 bullet configs for(Integer c : list) { //we can afford all this extra iteration trash on the count that a turret has at most like 4 bullet configs
BulletConfiguration conf = BulletConfigSyncingUtil.pullConfig(c); BulletConfiguration conf = BulletConfigSyncingUtil.pullConfig(c);
if(conf.ammo != null && conf.ammo.matchesRecipe(slots[i], true)) if(conf.ammo != null && conf.ammo.matchesRecipe(slots[i], true))
return conf; return conf;
} }
} }
} }
return null; return null;
} }
public void spawnBullet(BulletConfiguration bullet) { public void spawnBullet(BulletConfiguration bullet) {
Vec3 pos = this.getTurretPos(); Vec3 pos = this.getTurretPos();
Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0); Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0);
vec.rotateAroundZ((float) -this.rotationPitch); vec.rotateAroundZ((float) -this.rotationPitch);
vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5)); vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5));
EntityBulletBaseNT proj = new EntityBulletBaseNT(worldObj, BulletConfigSyncingUtil.getKey(bullet)); EntityBulletBaseNT proj = new EntityBulletBaseNT(worldObj, BulletConfigSyncingUtil.getKey(bullet));
proj.setPositionAndRotation(pos.xCoord + vec.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord, 0.0F, 0.0F); proj.setPositionAndRotation(pos.xCoord + vec.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord, 0.0F, 0.0F);
proj.setThrowableHeading(vec.xCoord, vec.yCoord, vec.zCoord, bullet.velocity, bullet.spread); proj.setThrowableHeading(vec.xCoord, vec.yCoord, vec.zCoord, bullet.velocity, bullet.spread);
worldObj.spawnEntityInWorld(proj); worldObj.spawnEntityInWorld(proj);
if(usesCasings()) { if(usesCasings()) {
if(this.casingDelay() == 0) { if(this.casingDelay() == 0) {
spawnCasing(); spawnCasing();
@ -375,118 +366,118 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
} }
} }
} }
public void conusmeAmmo(ComparableStack ammo) { public void conusmeAmmo(ComparableStack ammo) {
for(int i = 1; i < 10; i++) { for(int i = 1; i < 10; i++) {
if(slots[i] != null && ammo.matchesRecipe(slots[i], true)) { if(slots[i] != null && ammo.matchesRecipe(slots[i], true)) {
this.decrStackSize(i, 1); this.decrStackSize(i, 1);
return; return;
} }
} }
this.markDirty(); this.markDirty();
} }
/** /**
* Reads the namelist from the AI chip in slot 0 * Reads the namelist from the AI chip in slot 0
* @return null if there is either no chip to be found or if the name list is empty, otherwise it just reads the strings from the chip's NBT * @return null if there is either no chip to be found or if the name list is empty, otherwise it just reads the strings from the chip's NBT
*/ */
public List<String> getWhitelist() { public List<String> getWhitelist() {
if(slots[0] != null && slots[0].getItem() == ModItems.turret_chip) { if(slots[0] != null && slots[0].getItem() == ModItems.turret_chip) {
String[] array = ItemTurretBiometry.getNames(slots[0]); String[] array = ItemTurretBiometry.getNames(slots[0]);
if(array == null) if(array == null)
return null; return null;
return Arrays.asList(ItemTurretBiometry.getNames(slots[0])); return Arrays.asList(ItemTurretBiometry.getNames(slots[0]));
} }
return null; return null;
} }
/** /**
* Appends a new name to the chip * Appends a new name to the chip
* @param name * @param name
*/ */
public void addName(String name) { public void addName(String name) {
if(slots[0] != null && slots[0].getItem() == ModItems.turret_chip) { if(slots[0] != null && slots[0].getItem() == ModItems.turret_chip) {
ItemTurretBiometry.addName(slots[0], name); ItemTurretBiometry.addName(slots[0], name);
} }
} }
/** /**
* Removes the chip's entry at a given * Removes the chip's entry at a given
* @param index * @param index
*/ */
public void removeName(int index) { public void removeName(int index) {
if(slots[0] != null && slots[0].getItem() == ModItems.turret_chip) { if(slots[0] != null && slots[0].getItem() == ModItems.turret_chip) {
String[] array = ItemTurretBiometry.getNames(slots[0]); String[] array = ItemTurretBiometry.getNames(slots[0]);
if(array == null) if(array == null)
return; return;
List<String> names = new ArrayList(Arrays.asList(array)); List<String> names = new ArrayList(Arrays.asList(array));
ItemTurretBiometry.clearNames(slots[0]); ItemTurretBiometry.clearNames(slots[0]);
names.remove(index); names.remove(index);
for(String name : names) for(String name : names)
ItemTurretBiometry.addName(slots[0], name); ItemTurretBiometry.addName(slots[0], name);
} }
} }
/** /**
* Finds the nearest acceptable target within range and in line of sight * Finds the nearest acceptable target within range and in line of sight
*/ */
protected void seekNewTarget() { protected void seekNewTarget() {
Vec3 pos = this.getTurretPos(); Vec3 pos = this.getTurretPos();
double range = this.getDecetorRange(); double range = this.getDecetorRange();
List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(pos.xCoord, pos.yCoord, pos.zCoord, pos.xCoord, pos.yCoord, pos.zCoord).expand(range, range, range)); List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(pos.xCoord, pos.yCoord, pos.zCoord, pos.xCoord, pos.yCoord, pos.zCoord).expand(range, range, range));
Entity target = null; Entity target = null;
double closest = range; double closest = range;
for(Entity entity : entities) { for(Entity entity : entities) {
Vec3 ent = this.getEntityPos(entity); Vec3 ent = this.getEntityPos(entity);
Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord); Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord);
double dist = delta.lengthVector(); double dist = delta.lengthVector();
//check if it's in range //check if it's in range
if(dist > range) if(dist > range)
continue; continue;
//check if we should even fire at this entity //check if we should even fire at this entity
if(!entityAcceptableTarget(entity)) if(!entityAcceptableTarget(entity))
continue; continue;
//check for visibility //check for visibility
if(!entityInLOS(entity)) if(!entityInLOS(entity))
continue; continue;
//replace current target if this one is closer //replace current target if this one is closer
if(dist < closest) { if(dist < closest) {
closest = dist; closest = dist;
target = entity; target = entity;
} }
} }
this.target = target; this.target = target;
if(target != null) if(target != null)
this.tPos = this.getEntityPos(this.target); this.tPos = this.getEntityPos(this.target);
} }
/** /**
* Turns the turret by a specific amount of degrees towards the target * Turns the turret by a specific amount of degrees towards the target
* Assumes that the target is not null * Assumes that the target is not null
@ -494,7 +485,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
protected void alignTurret() { protected void alignTurret() {
this.turnTowards(tPos); this.turnTowards(tPos);
} }
/** /**
* Turns the turret towards the specified position * Turns the turret towards the specified position
*/ */
@ -502,32 +493,32 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
Vec3 pos = this.getTurretPos(); Vec3 pos = this.getTurretPos();
Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord); Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord);
double targetPitch = Math.asin(delta.yCoord / delta.lengthVector()); double targetPitch = Math.asin(delta.yCoord / delta.lengthVector());
double targetYaw = -Math.atan2(delta.xCoord, delta.zCoord); double targetYaw = -Math.atan2(delta.xCoord, delta.zCoord);
this.turnTowardsAngle(targetPitch, targetYaw); this.turnTowardsAngle(targetPitch, targetYaw);
} }
public void turnTowardsAngle(double targetPitch, double targetYaw) { public void turnTowardsAngle(double targetPitch, double targetYaw) {
double turnYaw = Math.toRadians(this.getTurretYawSpeed()); double turnYaw = Math.toRadians(this.getTurretYawSpeed());
double turnPitch = Math.toRadians(this.getTurretPitchSpeed()); double turnPitch = Math.toRadians(this.getTurretPitchSpeed());
double pi2 = Math.PI * 2; double pi2 = Math.PI * 2;
//if we are about to overshoot the target by turning, just snap to the correct rotation //if we are about to overshoot the target by turning, just snap to the correct rotation
if(Math.abs(this.rotationPitch - targetPitch) < turnPitch || Math.abs(this.rotationPitch - targetPitch) > pi2 - turnPitch) { if(Math.abs(this.rotationPitch - targetPitch) < turnPitch || Math.abs(this.rotationPitch - targetPitch) > pi2 - turnPitch) {
this.rotationPitch = targetPitch; this.rotationPitch = targetPitch;
} else { } else {
if(targetPitch > this.rotationPitch) if(targetPitch > this.rotationPitch)
this.rotationPitch += turnPitch; this.rotationPitch += turnPitch;
else else
this.rotationPitch -= turnPitch; this.rotationPitch -= turnPitch;
} }
double deltaYaw = (targetYaw - this.rotationYaw) % pi2; double deltaYaw = (targetYaw - this.rotationYaw) % pi2;
//determines what direction the turret should turn //determines what direction the turret should turn
//used to prevent situations where the turret would do almost a full turn when //used to prevent situations where the turret would do almost a full turn when
//the target is only a couple degrees off while being on the other side of the 360° line //the target is only a couple degrees off while being on the other side of the 360° line
@ -541,68 +532,68 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
dir = -1; dir = -1;
else if(deltaYaw > 0) else if(deltaYaw > 0)
dir = 1; dir = 1;
if(Math.abs(this.rotationYaw - targetYaw) < turnYaw || Math.abs(this.rotationYaw - targetYaw) > pi2 - turnYaw) { if(Math.abs(this.rotationYaw - targetYaw) < turnYaw || Math.abs(this.rotationYaw - targetYaw) > pi2 - turnYaw) {
this.rotationYaw = targetYaw; this.rotationYaw = targetYaw;
} else { } else {
this.rotationYaw += turnYaw * dir; this.rotationYaw += turnYaw * dir;
} }
double deltaPitch = targetPitch - this.rotationPitch; double deltaPitch = targetPitch - this.rotationPitch;
deltaYaw = targetYaw - this.rotationYaw; deltaYaw = targetYaw - this.rotationYaw;
double deltaAngle = Math.sqrt(deltaYaw * deltaYaw + deltaPitch * deltaPitch); double deltaAngle = Math.sqrt(deltaYaw * deltaYaw + deltaPitch * deltaPitch);
this.rotationYaw = this.rotationYaw % pi2; this.rotationYaw = this.rotationYaw % pi2;
this.rotationPitch = this.rotationPitch % pi2; this.rotationPitch = this.rotationPitch % pi2;
if(deltaAngle <= Math.toRadians(this.getAcceptableInaccuracy())) { if(deltaAngle <= Math.toRadians(this.getAcceptableInaccuracy())) {
this.aligned = true; this.aligned = true;
} }
} }
/** /**
* Checks line of sight to the passed entity along with whether the angle falls within swivel range * Checks line of sight to the passed entity along with whether the angle falls within swivel range
* @return * @return
*/ */
public boolean entityInLOS(Entity e) { public boolean entityInLOS(Entity e) {
if(e.isDead || !e.isEntityAlive()) if(e.isDead || !e.isEntityAlive())
return false; return false;
if(!hasThermalVision() && e instanceof EntityLivingBase && ((EntityLivingBase)e).isPotionActive(Potion.invisibility)) if(!hasThermalVision() && e instanceof EntityLivingBase && ((EntityLivingBase)e).isPotionActive(Potion.invisibility))
return false; return false;
Vec3 pos = this.getTurretPos(); Vec3 pos = this.getTurretPos();
Vec3 ent = this.getEntityPos(e); Vec3 ent = this.getEntityPos(e);
Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord); Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord);
double length = delta.lengthVector(); double length = delta.lengthVector();
if(length < this.getDecetorGrace() || length > this.getDecetorRange() * 1.1) //the latter statement is only relevant for entities that have already been detected if(length < this.getDecetorGrace() || length > this.getDecetorRange() * 1.1) //the latter statement is only relevant for entities that have already been detected
return false; return false;
delta = delta.normalize(); delta = delta.normalize();
double pitch = Math.asin(delta.yCoord / delta.lengthVector()); double pitch = Math.asin(delta.yCoord / delta.lengthVector());
double pitchDeg = Math.toDegrees(pitch); double pitchDeg = Math.toDegrees(pitch);
//check if the entity is within swivel range //check if the entity is within swivel range
if(pitchDeg < -this.getTurretDepression() || pitchDeg > this.getTurretElevation()) if(pitchDeg < -this.getTurretDepression() || pitchDeg > this.getTurretElevation())
return false; return false;
return !Library.isObstructedOpaque(worldObj, ent.xCoord, ent.yCoord, ent.zCoord, pos.xCoord, pos.yCoord, pos.zCoord); return !Library.isObstructedOpaque(worldObj, ent.xCoord, ent.yCoord, ent.zCoord, pos.xCoord, pos.yCoord, pos.zCoord);
} }
/** /**
* Returns true if the entity is considered for targeting * Returns true if the entity is considered for targeting
* @return * @return
*/ */
public boolean entityAcceptableTarget(Entity e) { public boolean entityAcceptableTarget(Entity e) {
if(e.isDead || !e.isEntityAlive()) if(e.isDead || !e.isEntityAlive())
return false; return false;
for(Class c : CompatExternal.turretTargetBlacklist) if(c.isAssignableFrom(e.getClass())) return false; for(Class c : CompatExternal.turretTargetBlacklist) if(c.isAssignableFrom(e.getClass())) return false;
for(Class c : CompatExternal.turretTargetCondition.keySet()) { for(Class c : CompatExternal.turretTargetCondition.keySet()) {
if(c.isAssignableFrom(e.getClass())) { if(c.isAssignableFrom(e.getClass())) {
BiFunction<Entity, Object, Integer> lambda = CompatExternal.turretTargetCondition.get(c); BiFunction<Entity, Object, Integer> lambda = CompatExternal.turretTargetCondition.get(c);
@ -615,9 +606,9 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
} }
List<String> wl = getWhitelist(); List<String> wl = getWhitelist();
if(wl != null) { if(wl != null) {
if(e instanceof EntityPlayer) { if(e instanceof EntityPlayer) {
if(wl.contains(((EntityPlayer)e).getDisplayName())) { if(wl.contains(((EntityPlayer)e).getDisplayName())) {
return false; return false;
@ -628,14 +619,14 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
} }
} }
} }
if(targetAnimals) { if(targetAnimals) {
if(e instanceof IAnimals) return true; if(e instanceof IAnimals) return true;
if(e instanceof INpc) return true; if(e instanceof INpc) return true;
for(Class c : CompatExternal.turretTargetFriendly) if(c.isAssignableFrom(e.getClass())) return true; for(Class c : CompatExternal.turretTargetFriendly) if(c.isAssignableFrom(e.getClass())) return true;
} }
if(targetMobs) { if(targetMobs) {
//never target the ender dragon directly //never target the ender dragon directly
@ -644,7 +635,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
if(e instanceof IMob) return true; if(e instanceof IMob) return true;
for(Class c : CompatExternal.turretTargetHostile) if(c.isAssignableFrom(e.getClass())) return true; for(Class c : CompatExternal.turretTargetHostile) if(c.isAssignableFrom(e.getClass())) return true;
} }
if(targetMachines) { if(targetMachines) {
if(e instanceof IRadarDetectableNT && !((IRadarDetectableNT)e).canBeSeenBy(this)) return false; if(e instanceof IRadarDetectableNT && !((IRadarDetectableNT)e).canBeSeenBy(this)) return false;
@ -655,17 +646,17 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
if(e instanceof EntityBomber) return true; if(e instanceof EntityBomber) return true;
for(Class c : CompatExternal.turretTargetMachine) if(c.isAssignableFrom(e.getClass())) return true; for(Class c : CompatExternal.turretTargetMachine) if(c.isAssignableFrom(e.getClass())) return true;
} }
if(targetPlayers ) { if(targetPlayers ) {
if(e instanceof FakePlayer) return false; if(e instanceof FakePlayer) return false;
if(e instanceof EntityPlayer) return true; if(e instanceof EntityPlayer) return true;
for(Class c : CompatExternal.turretTargetPlayer) if(c.isAssignableFrom(e.getClass())) return true; for(Class c : CompatExternal.turretTargetPlayer) if(c.isAssignableFrom(e.getClass())) return true;
} }
return false; return false;
} }
/** /**
* How many degrees the turret can deviate from the target to be acceptable to fire at * How many degrees the turret can deviate from the target to be acceptable to fire at
* @return * @return
@ -673,7 +664,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public double getAcceptableInaccuracy() { public double getAcceptableInaccuracy() {
return 5; return 5;
} }
/** /**
* How many degrees the turret can rotate per tick (4.5°/t = 90°/s or a half turn in two seconds) * How many degrees the turret can rotate per tick (4.5°/t = 90°/s or a half turn in two seconds)
* @return * @return
@ -681,7 +672,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public double getTurretYawSpeed() { public double getTurretYawSpeed() {
return 4.5D; return 4.5D;
} }
/** /**
* How many degrees the turret can lift per tick (3°/t = 60°/s or roughly the lowest to the highest point of an average turret in one second) * How many degrees the turret can lift per tick (3°/t = 60°/s or roughly the lowest to the highest point of an average turret in one second)
* @return * @return
@ -705,7 +696,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public double getTurretElevation() { public double getTurretElevation() {
return 30D; return 30D;
} }
/** /**
* How many ticks until a target rescan is required * How many ticks until a target rescan is required
* @return * @return
@ -713,7 +704,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public int getDecetorInterval() { public int getDecetorInterval() {
return 10; return 10;
} }
/** /**
* How far away an entity can be to be picked up * How far away an entity can be to be picked up
* @return * @return
@ -721,7 +712,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public double getDecetorRange() { public double getDecetorRange() {
return 32D; return 32D;
} }
/** /**
* How far away an entity needs to be to be picked up * How far away an entity needs to be to be picked up
* @return * @return
@ -729,7 +720,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public double getDecetorGrace() { public double getDecetorGrace() {
return 3D; return 3D;
} }
/** /**
* The pivot point of the turret, larger models have a default of 1.5 * The pivot point of the turret, larger models have a default of 1.5
* @return * @return
@ -737,7 +728,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public double getHeightOffset() { public double getHeightOffset() {
return 1.5D; return 1.5D;
} }
/** /**
* Horizontal offset for the spawn point of bullets * Horizontal offset for the spawn point of bullets
* @return * @return
@ -753,7 +744,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public boolean hasThermalVision() { public boolean hasThermalVision() {
return true; return true;
} }
/** /**
* The pivot point of the turret, this position is used for LOS calculation and more * The pivot point of the turret, this position is used for LOS calculation and more
* @return * @return
@ -762,7 +753,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
Vec3 offset = getHorizontalOffset(); Vec3 offset = getHorizontalOffset();
return Vec3.createVectorHelper(xCoord + offset.xCoord, yCoord + getHeightOffset(), zCoord + offset.zCoord); return Vec3.createVectorHelper(xCoord + offset.xCoord, yCoord + getHeightOffset(), zCoord + offset.zCoord);
} }
/** /**
* The XZ offset for a standard 2x2 turret base * The XZ offset for a standard 2x2 turret base
* @return * @return
@ -776,10 +767,10 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
return Vec3.createVectorHelper(1, 0, 0); return Vec3.createVectorHelper(1, 0, 0);
if(meta == 5) if(meta == 5)
return Vec3.createVectorHelper(0, 0, 1); return Vec3.createVectorHelper(0, 0, 1);
return Vec3.createVectorHelper(0, 0, 0); return Vec3.createVectorHelper(0, 0, 0);
} }
/** /**
* The pivot point of the turret, this position is used for LOS calculation and more * The pivot point of the turret, this position is used for LOS calculation and more
* @return * @return
@ -787,32 +778,32 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public Vec3 getEntityPos(Entity e) { public Vec3 getEntityPos(Entity e) {
return Vec3.createVectorHelper(e.posX, e.posY + e.height * 0.5 - e.getYOffset(), e.posZ); return Vec3.createVectorHelper(e.posX, e.posY + e.height * 0.5 - e.getYOffset(), e.posZ);
} }
/** /**
* Yes, new turrets fire BulletNTs. * Yes, new turrets fire BulletNTs.
* @return * @return
*/ */
protected abstract List<Integer> getAmmoList(); protected abstract List<Integer> getAmmoList();
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
protected List<ItemStack> ammoStacks; protected List<ItemStack> ammoStacks;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public List<ItemStack> getAmmoTypesForDisplay() { public List<ItemStack> getAmmoTypesForDisplay() {
if(ammoStacks != null) if(ammoStacks != null)
return ammoStacks; return ammoStacks;
ammoStacks = new ArrayList(); ammoStacks = new ArrayList();
for(Integer i : getAmmoList()) { for(Integer i : getAmmoList()) {
BulletConfiguration config = BulletConfigSyncingUtil.pullConfig(i); BulletConfiguration config = BulletConfigSyncingUtil.pullConfig(i);
if(config != null && config.ammo != null) { if(config != null && config.ammo != null) {
ammoStacks.add(config.ammo.toStack()); ammoStacks.add(config.ammo.toStack());
} }
} }
return ammoStacks; return ammoStacks;
} }
@ -829,11 +820,11 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public boolean hasPower() { public boolean hasPower() {
return this.getPower() >= this.getConsumption(); return this.getPower() >= this.getConsumption();
} }
public boolean isOn() { public boolean isOn() {
return this.isOn; return this.isOn;
} }
@Override @Override
public void setPower(long i) { public void setPower(long i) {
this.power = i; this.power = i;
@ -843,15 +834,15 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public long getPower() { public long getPower() {
return this.power; return this.power;
} }
public int getPowerScaled(int scale) { public int getPowerScaled(int scale) {
return (int)(power * scale / this.getMaxPower()); return (int)(power * scale / this.getMaxPower());
} }
public long getConsumption() { public long getConsumption() {
return 100; return 100;
} }
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB; return TileEntity.INFINITE_EXTENT_AABB;
@ -872,20 +863,20 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
public void closeInventory() { public void closeInventory() {
this.worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:block.closeC", 1.0F, 1.0F); this.worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:block.closeC", 1.0F, 1.0F);
} }
protected Vec3 getCasingSpawnPos() { protected Vec3 getCasingSpawnPos() {
return this.getTurretPos(); return this.getTurretPos();
} }
protected CasingEjector getEjector() { protected CasingEjector getEjector() {
return null; return null;
} }
protected void spawnCasing() { protected void spawnCasing() {
if(cachedCasingConfig == null) return; if(cachedCasingConfig == null) return;
CasingEjector ej = getEjector(); CasingEjector ej = getEjector();
Vec3 spawn = this.getCasingSpawnPos(); Vec3 spawn = this.getCasingSpawnPos();
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "casing"); data.setString("type", "casing");
@ -895,10 +886,10 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
data.setString("name", cachedCasingConfig.getName()); data.setString("name", cachedCasingConfig.getName());
if(ej != null) data.setInteger("ej", ej.getId()); if(ej != null) data.setInteger("ej", ej.getId());
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, spawn.xCoord, spawn.yCoord, spawn.zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, spawn.xCoord, spawn.yCoord, spawn.zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
cachedCasingConfig = null; cachedCasingConfig = null;
} }
@Override @Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerTurretBase(player.inventory, this); return new ContainerTurretBase(player.inventory, this);

View File

@ -44,10 +44,10 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public List<ItemStack> getAmmoTypesForDisplay() { public List<ItemStack> getAmmoTypesForDisplay() {
if(ammoStacks != null) if(ammoStacks != null)
return ammoStacks; return ammoStacks;
ammoStacks = new ArrayList(); ammoStacks = new ArrayList();
ammoStacks.add(new ItemStack(ModItems.upgrade_speed_1)); ammoStacks.add(new ItemStack(ModItems.upgrade_speed_1));
@ -67,7 +67,7 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
ammoStacks.add(new ItemStack(ModItems.upgrade_overdrive_3)); ammoStacks.add(new ItemStack(ModItems.upgrade_overdrive_3));
ammoStacks.add(new ItemStack(ModItems.upgrade_5g)); ammoStacks.add(new ItemStack(ModItems.upgrade_5g));
ammoStacks.add(new ItemStack(ModItems.upgrade_screm)); ammoStacks.add(new ItemStack(ModItems.upgrade_screm));
return ammoStacks; return ammoStacks;
} }
@ -105,7 +105,7 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
if(type == UpgradeType.OVERDRIVE) return 27; if(type == UpgradeType.OVERDRIVE) return 27;
return 0; return 0;
} }
@Override @Override
public double getAcceptableInaccuracy() { public double getAcceptableInaccuracy() {
return 2; return 2;
@ -160,28 +160,28 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
public double getHeightOffset() { public double getHeightOffset() {
return 2D; return 2D;
} }
public int beam; public int beam;
public double lastDist; public double lastDist;
@Override @Override
public void updateEntity() { public void updateEntity() {
if(worldObj.isRemote) { if(worldObj.isRemote) {
if(this.tPos != null) { if(this.tPos != null) {
Vec3 pos = this.getTurretPos(); Vec3 pos = this.getTurretPos();
double length = Vec3.createVectorHelper(tPos.xCoord - pos.xCoord, tPos.yCoord - pos.yCoord, tPos.zCoord - pos.zCoord).lengthVector(); double length = Vec3.createVectorHelper(tPos.xCoord - pos.xCoord, tPos.yCoord - pos.yCoord, tPos.zCoord - pos.zCoord).lengthVector();
this.lastDist = length; this.lastDist = length;
} }
if(beam > 0) if(beam > 0)
beam--; beam--;
} else { } else {
if(checkDelay <= 0) { if(checkDelay <= 0) {
checkDelay = 20; checkDelay = 20;
this.redLevel = 0; this.redLevel = 0;
this.greenLevel = 0; this.greenLevel = 0;
this.blueLevel = 0; this.blueLevel = 0;
@ -189,11 +189,11 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
this.pinkLevel = 0; this.pinkLevel = 0;
this._5g = false; this._5g = false;
this.screm = false; this.screm = false;
for(int i = 1; i < 10; i++) { for(int i = 1; i < 10; i++) {
if(slots[i] != null) { if(slots[i] != null) {
Item item = slots[i].getItem(); Item item = slots[i].getItem();
if(item == ModItems.upgrade_speed_1) redLevel += 1; if(item == ModItems.upgrade_speed_1) redLevel += 1;
if(item == ModItems.upgrade_speed_2) redLevel += 2; if(item == ModItems.upgrade_speed_2) redLevel += 2;
if(item == ModItems.upgrade_speed_3) redLevel += 3; if(item == ModItems.upgrade_speed_3) redLevel += 3;
@ -214,13 +214,13 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
} }
} }
} }
checkDelay--; checkDelay--;
} }
super.updateEntity(); super.updateEntity();
} }
int redLevel; int redLevel;
int greenLevel; int greenLevel;
int blueLevel; int blueLevel;
@ -228,14 +228,14 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
int pinkLevel; int pinkLevel;
boolean _5g; boolean _5g;
boolean screm; boolean screm;
int checkDelay; int checkDelay;
@Override @Override
public void updateFiringTick() { public void updateFiringTick() {
long demand = this.getConsumption() * 10; long demand = this.getConsumption() * 10;
if(this.target != null && this.getPower() >= demand) { if(this.target != null && this.getPower() >= demand) {
if(_5g && target instanceof EntityPlayer) { if(_5g && target instanceof EntityPlayer) {
@ -244,38 +244,37 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
} else { } else {
EntityDamageUtil.attackEntityFromIgnoreIFrame(this.target, ModDamageSource.microwave, (this.blackLevel * 10 + this.redLevel + 1F) * 0.25F); EntityDamageUtil.attackEntityFromIgnoreIFrame(this.target, ModDamageSource.microwave, (this.blackLevel * 10 + this.redLevel + 1F) * 0.25F);
} }
if(pinkLevel > 0) if(pinkLevel > 0)
this.target.setFire(this.pinkLevel * 3); this.target.setFire(this.pinkLevel * 3);
if(!this.target.isEntityAlive() && this.target instanceof EntityLivingBase) { if(!this.target.isEntityAlive() && this.target instanceof EntityLivingBase) {
NBTTagCompound vdat = new NBTTagCompound(); NBTTagCompound vdat = new NBTTagCompound();
vdat.setString("type", "giblets"); vdat.setString("type", "giblets");
vdat.setInteger("ent", this.target.getEntityId()); vdat.setInteger("ent", this.target.getEntityId());
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(vdat, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ), new TargetPoint(this.target.dimension, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ, 150)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(vdat, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ), new TargetPoint(this.target.dimension, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ, 150));
if(this.screm) if(this.screm)
worldObj.playSoundEffect(this.target.posX, this.target.posY, this.target.posZ, "hbm:block.screm", 20.0F, 1.0F); worldObj.playSoundEffect(this.target.posX, this.target.posY, this.target.posZ, "hbm:block.screm", 20.0F, 1.0F);
else else
worldObj.playSoundEffect(this.target.posX, this.target.posY, this.target.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F); worldObj.playSoundEffect(this.target.posX, this.target.posY, this.target.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F);
} }
this.power -= demand; this.power -= demand;
this.networkPackNT(250); this.networkPackNT(250);
} }
} }
@Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf);
buf.writeBoolean(true); buf.writeBoolean(true);
} }
@Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); if(buf.readBoolean())
this.beam = buf.readBoolean() ? 5 : 0; this.beam = 5;
else
this.beam = 0;
} }
@Override @Override

View File

@ -36,7 +36,7 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
public double lastBarrelRightPos = 0; public double lastBarrelRightPos = 0;
static List<Integer> configs = new ArrayList(); static List<Integer> configs = new ArrayList();
static { static {
configs.add(BulletConfigSyncingUtil.R5_NORMAL); configs.add(BulletConfigSyncingUtil.R5_NORMAL);
configs.add(BulletConfigSyncingUtil.R5_EXPLOSIVE); configs.add(BulletConfigSyncingUtil.R5_EXPLOSIVE);
@ -44,7 +44,7 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
configs.add(BulletConfigSyncingUtil.R5_STAR); configs.add(BulletConfigSyncingUtil.R5_STAR);
configs.add(BulletConfigSyncingUtil.CHL_R5); configs.add(BulletConfigSyncingUtil.CHL_R5);
} }
@Override @Override
protected List<Integer> getAmmoList() { protected List<Integer> getAmmoList() {
return configs; return configs;
@ -54,7 +54,7 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
public String getName() { public String getName() {
return "container.turretSentry"; return "container.turretSentry";
} }
@Override @Override
public double getTurretDepression() { public double getTurretDepression() {
return 20D; return 20D;
@ -109,38 +109,38 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
public Vec3 getHorizontalOffset() { public Vec3 getHorizontalOffset() {
return Vec3.createVectorHelper(0.5, 0, 0.5); return Vec3.createVectorHelper(0.5, 0, 0.5);
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(worldObj.isRemote) { if(worldObj.isRemote) {
this.lastBarrelLeftPos = this.barrelLeftPos; this.lastBarrelLeftPos = this.barrelLeftPos;
this.lastBarrelRightPos = this.barrelRightPos; this.lastBarrelRightPos = this.barrelRightPos;
float retractSpeed = 0.5F; float retractSpeed = 0.5F;
float pushSpeed = 0.25F; float pushSpeed = 0.25F;
if(this.retractingLeft) { if(this.retractingLeft) {
this.barrelLeftPos += retractSpeed; this.barrelLeftPos += retractSpeed;
if(this.barrelLeftPos >= 1) { if(this.barrelLeftPos >= 1) {
this.retractingLeft = false; this.retractingLeft = false;
} }
} else { } else {
this.barrelLeftPos -= pushSpeed; this.barrelLeftPos -= pushSpeed;
if(this.barrelLeftPos < 0) { if(this.barrelLeftPos < 0) {
this.barrelLeftPos = 0; this.barrelLeftPos = 0;
} }
} }
if(this.retractingRight) { if(this.retractingRight) {
this.barrelRightPos += retractSpeed; this.barrelRightPos += retractSpeed;
if(this.barrelRightPos >= 1) { if(this.barrelRightPos >= 1) {
this.retractingRight = false; this.retractingRight = false;
} }
} else { } else {
this.barrelRightPos -= pushSpeed; this.barrelRightPos -= pushSpeed;
if(this.barrelRightPos < 0) { if(this.barrelRightPos < 0) {
@ -148,43 +148,43 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
} }
} }
} }
super.updateEntity(); super.updateEntity();
} }
boolean shotSide = false; boolean shotSide = false;
int timer; int timer;
@Override @Override
public void updateFiringTick() { public void updateFiringTick() {
timer++; timer++;
if(timer % 10 == 0) { if(timer % 10 == 0) {
BulletConfiguration conf = this.getFirstConfigLoaded(); BulletConfiguration conf = this.getFirstConfigLoaded();
if(conf != null) { if(conf != null) {
this.cachedCasingConfig = conf.spentCasing; this.cachedCasingConfig = conf.spentCasing;
this.spawnBullet(conf); this.spawnBullet(conf);
this.conusmeAmmo(conf.ammo); this.conusmeAmmo(conf.ammo);
this.worldObj.playSoundEffect(xCoord, yCoord, zCoord, "hbm:turret.sentry_fire", 2.0F, 1.0F); this.worldObj.playSoundEffect(xCoord, yCoord, zCoord, "hbm:turret.sentry_fire", 2.0F, 1.0F);
Vec3 pos = this.getTurretPos(); Vec3 pos = this.getTurretPos();
Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0); Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0);
vec.rotateAroundZ((float) -this.rotationPitch); vec.rotateAroundZ((float) -this.rotationPitch);
vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5)); vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5));
Vec3 side = Vec3.createVectorHelper(0.125 * (shotSide ? 1 : -1), 0, 0); Vec3 side = Vec3.createVectorHelper(0.125 * (shotSide ? 1 : -1), 0, 0);
side.rotateAroundY((float) -(this.rotationYaw)); side.rotateAroundY((float) -(this.rotationYaw));
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaExt"); data.setString("type", "vanillaExt");
data.setString("mode", "largeexplode"); data.setString("mode", "largeexplode");
data.setFloat("size", 1F); data.setFloat("size", 1F);
data.setByte("count", (byte)1); data.setByte("count", (byte)1);
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.xCoord + vec.xCoord + side.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord + side.zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.xCoord + vec.xCoord + side.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord + side.zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
if(shotSide) { if(shotSide) {
this.didJustShootLeft = true; this.didJustShootLeft = true;
} else { } else {
@ -197,32 +197,32 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
@Override @Override
protected Vec3 getCasingSpawnPos() { protected Vec3 getCasingSpawnPos() {
Vec3 pos = this.getTurretPos(); Vec3 pos = this.getTurretPos();
Vec3 vec = Vec3.createVectorHelper(0, 0.25,-0.125); Vec3 vec = Vec3.createVectorHelper(0, 0.25,-0.125);
vec.rotateAroundZ((float) -this.rotationPitch); vec.rotateAroundZ((float) -this.rotationPitch);
vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5)); vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5));
return Vec3.createVectorHelper(pos.xCoord + vec.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord); return Vec3.createVectorHelper(pos.xCoord + vec.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord);
} }
protected static CasingEjector ejector = new CasingEjector().setMotion(-0.3, 0.6, 0).setAngleRange(0.01F, 0.01F); protected static CasingEjector ejector = new CasingEjector().setMotion(-0.3, 0.6, 0).setAngleRange(0.01F, 0.01F);
@Override @Override
protected CasingEjector getEjector() { protected CasingEjector getEjector() {
return ejector.setMotion(0.3, 0.6, 0); return ejector.setMotion(0.3, 0.6, 0);
} }
@Override @Override
public boolean usesCasings() { public boolean usesCasings() {
return true; return true;
} }
@Override @Override
protected void seekNewTarget() { protected void seekNewTarget() {
Entity lastTarget = this.target; Entity lastTarget = this.target;
super.seekNewTarget(); super.seekNewTarget();
if(lastTarget != this.target && this.target != null) { if(lastTarget != this.target && this.target != null) {
worldObj.playSoundAtEntity(target, "hbm:turret.sentry_lockon", 2.0F, 1.5F); worldObj.playSoundAtEntity(target, "hbm:turret.sentry_lockon", 2.0F, 1.5F);
} }
@ -231,8 +231,8 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
if(didJustShootLeft) buf.writeBoolean(didJustShootLeft); buf.writeBoolean(didJustShootLeft);
if(didJustShootRight) buf.writeBoolean(didJustShootRight); buf.writeBoolean(didJustShootRight);
didJustShootLeft = false; didJustShootLeft = false;
didJustShootRight = false; didJustShootRight = false;
} }
@ -240,10 +240,10 @@ public class TileEntityTurretSentry extends TileEntityTurretBaseNT implements IG
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
if(buf.readBoolean()) this.retractingLeft = true; this.retractingLeft = buf.readBoolean();
if(buf.readBoolean()) this.retractingRight = true; this.retractingRight = buf.readBoolean();
} }
protected void updateConnections() { protected void updateConnections() {
this.trySubscribe(worldObj, xCoord, yCoord - 1, zCoord, ForgeDirection.DOWN); this.trySubscribe(worldObj, xCoord, yCoord - 1, zCoord, ForgeDirection.DOWN);
} }

View File

@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker; import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
public class BufferUtil { public class BufferUtil {
@ -62,6 +63,32 @@ public class BufferUtil {
return array; return array;
} }
/**
* Writes a vector to a buffer.
*/
public static void writeVec3(ByteBuf buf, Vec3 vector) {
buf.writeBoolean(vector != null);
if(vector == null) return;
buf.writeDouble(vector.xCoord);
buf.writeDouble(vector.yCoord);
buf.writeDouble(vector.zCoord);
}
/**
* Reads a vector from a buffer.
*/
public static Vec3 readVec3(ByteBuf buf) {
boolean vectorExists = buf.readBoolean();
if(!vectorExists) {
return null;
}
double x = buf.readDouble();
double y = buf.readDouble();
double z = buf.readDouble();
return Vec3.createVectorHelper(x, y, z);
}
/** /**
* Writes a NBTTagCompound to a buffer. * Writes a NBTTagCompound to a buffer.
*/ */
@ -131,4 +158,4 @@ public class BufferUtil {
} }
return item; return item;
} }
} }