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.tank.FluidTank;
import com.hbm.saveddata.TomSaveData;
import com.hbm.tileentity.IBufPacketReceiver;
import com.hbm.tileentity.IFluidCopiable;
import com.hbm.tileentity.IConfigurableMachine;
import com.hbm.tileentity.TileEntityLoadedBase;
@ -22,10 +23,10 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
public int age = 0;
public FluidTank[] tanks;
public int waterTimer = 0;
protected int throughput;
//Configurable values
public static int inputTankSize = 100;
public static int outputTankSize = 100;
@ -55,49 +56,49 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
age++;
if(age >= 2) {
age = 0;
}
NBTTagCompound data = new NBTTagCompound();
this.tanks[0].writeToNBT(data, "0");
if(this.waterTimer > 0)
this.waterTimer--;
int convert = Math.min(tanks[0].getFill(), tanks[1].getMaxFill() - tanks[1].getFill());
this.throughput = convert;
if(extraCondition(convert)) {
tanks[0].setFill(tanks[0].getFill() - convert);
if(convert > 0)
this.waterTimer = 20;
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...
tanks[1].setFill(tanks[1].getFill() - convert);
} else {
tanks[1].setFill(tanks[1].getFill() + convert);
}
postConvert(convert);
}
this.tanks[1].writeToNBT(data, "1");
this.subscribeToAllAround(tanks[0].getTankType(), this);
this.sendFluidToAll(tanks[1], this);
sendStandard(150);
}
}
public void packExtra(NBTTagCompound data) { }
public boolean extraCondition(int convert) { return true; }
public void postConvert(int convert) { }
@ -115,14 +116,14 @@ public class TileEntityCondenser extends TileEntityLoadedBase implements IFluidS
this.tanks[1].deserialize(buf);
this.waterTimer = buf.readByte();
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
tanks[0].readFromNBT(nbt, "water");
tanks[1].readFromNBT(nbt, "steam");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);

View File

@ -50,7 +50,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
public int heat;
public int progress;
public List<MaterialStack> recipeStack = new ArrayList();
public List<MaterialStack> wasteStack = new ArrayList();
@ -102,21 +102,21 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
tryPullHeat();
/* collect items */
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));
for(EntityItem item : list) {
ItemStack stack = item.getEntityItem();
if(this.isItemSmeltable(stack)) {
for(int i = 1; i < 10; i++) {
if(slots[i] == null) {
if(stack.stackSize == 1) {
slots[i] = stack.copy();
item.setDead();
@ -126,7 +126,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
slots[i].stackSize = 1;
stack.stackSize--;
}
this.markChanged();
}
}
@ -139,29 +139,29 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
for(MaterialStack stack : recipeStack) totalMass += stack.amount;
for(MaterialStack stack : wasteStack) totalMass += stack.amount;
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));
for(EntityLivingBase entity : living) {
entity.attackEntityFrom(DamageSource.lava, 5F);
entity.setFire(5);
}
/* smelt items from buffer */
if(!trySmelt()) {
this.progress = 0;
}
tryRecipe();
/* pour waste stack */
if(!this.wasteStack.isEmpty()) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
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);
if(didPour != null) {
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "foundry");
@ -171,24 +171,24 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
data.setFloat("base", 0.625F);
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));
}
PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 20F);
}
/* pour recipe stack */
if(!this.recipeStack.isEmpty()) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
List<MaterialStack> toCast = new ArrayList();
CrucibleRecipe recipe = this.getLoadedRecipe();
//if no recipe is loaded, everything from the recipe stack will be drainable
if(recipe == null) {
toCast.addAll(this.recipeStack);
} else {
for(MaterialStack stack : this.recipeStack) {
for(MaterialStack output : recipe.output) {
if(stack.material == output.material) {
@ -198,7 +198,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
}
}
}
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);
@ -211,7 +211,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
data.setFloat("base", 0.625F);
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));
}
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 */
this.recipeStack.removeIf(o -> o.amount <= 0);
this.wasteStack.removeIf(x -> x.amount <= 0);
/* sync */
this.networkPackNT(25);
}
}
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
buf.writeInt(progress);
buf.writeInt(heat);
buf.writeShort(recipeStack.size());
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.writeShort(wasteStack.size());
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);
}
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
progress = buf.readInt();
heat = buf.readInt();
recipeStack.clear();
wasteStack.clear();
int mats = buf.readShort();
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();
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
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
@ -273,20 +285,20 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
for(int i = 0; i < rec.length / 2; i++) {
recipeStack.add(new MaterialStack(Mats.matById.get(rec[i * 2]), rec[i * 2 + 1]));
}
int[] was = nbt.getIntArray("was");
for(int i = 0; i < was.length / 2; i++) {
wasteStack.add(new MaterialStack(Mats.matById.get(was[i * 2]), was[i * 2 + 1]));
}
this.progress = nbt.getInteger("progress");
this.heat = nbt.getInteger("heat");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
int[] rec = new int[recipeStack.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; }
@ -296,21 +308,21 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
nbt.setInteger("progress", progress);
nbt.setInteger("heat", heat);
}
protected void tryPullHeat() {
if(this.heat >= this.maxHeat) return;
TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
if(con instanceof IHeatSource) {
IHeatSource source = (IHeatSource) con;
int diff = source.getHeatStored() - this.heat;
if(diff == 0) {
return;
}
if(diff > 0) {
diff = (int) Math.ceil(diff * diffusion);
source.useUpHeat(diff);
@ -320,170 +332,170 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
return;
}
}
this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0);
}
protected boolean trySmelt() {
if(this.heat < maxHeat / 2) return false;
int slot = this.getFirstSmeltableSlot();
if(slot == -1) return false;
int delta = this.heat - (maxHeat / 2);
delta *= 0.05;
this.progress += delta;
this.heat -= delta;
if(this.progress >= processTime) {
this.progress = 0;
List<MaterialStack> materials = Mats.getSmeltingMaterialsFromItem(slots[slot]);
CrucibleRecipe recipe = getLoadedRecipe();
for(MaterialStack material : materials) {
boolean mainStack = recipe != null && (getQuantaFromType(recipe.input, material.material) > 0 || getQuantaFromType(recipe.output, material.material) > 0);
if(mainStack) {
this.addToStack(this.recipeStack, material);
} else {
this.addToStack(this.wasteStack, material);
}
}
this.decrStackSize(slot, 1);
}
return true;
}
protected void tryRecipe() {
CrucibleRecipe recipe = this.getLoadedRecipe();
if(recipe == null) return;
if(worldObj.getTotalWorldTime() % recipe.frequency > 0) return;
for(MaterialStack stack : recipe.input) {
if(getQuantaFromType(this.recipeStack, stack.material) < stack.amount) return;
}
for(MaterialStack stack : this.recipeStack) {
stack.amount -= getQuantaFromType(recipe.input, stack.material);
}
outer:
for(MaterialStack out : recipe.output) {
for(MaterialStack stack : this.recipeStack) {
if(stack.material == out.material) {
stack.amount += out.amount;
continue outer;
}
}
this.recipeStack.add(out.copy());
}
}
protected int getFirstSmeltableSlot() {
for(int i = 1; i < 10; i++) {
ItemStack stack = slots[i];
if(stack != null && isItemSmeltable(stack)) {
return i;
}
}
return -1;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack) {
if(i == 0) {
return stack.getItem() == ModItems.crucible_template;
}
return isItemSmeltable(stack);
}
public boolean isItemSmeltable(ItemStack stack) {
List<MaterialStack> materials = Mats.getSmeltingMaterialsFromItem(stack);
//if there's no materials in there at all, don't smelt
if(materials.isEmpty())
return false;
CrucibleRecipe recipe = getLoadedRecipe();
//needs to be true, will always be true if there's no recipe loaded
boolean matchesRecipe = recipe == null;
//the amount of material in the entire recipe input
int recipeContent = recipe != null ? recipe.getInputAmount() : 0;
//the total amount of the current waste stack, used for simulation
int recipeAmount = getQuantaFromType(this.recipeStack, null);
int wasteAmount = getQuantaFromType(this.wasteStack, null);
for(MaterialStack mat : materials) {
//if no recipe is loaded, everything will land in the waste stack
int recipeInputRequired = recipe != null ? getQuantaFromType(recipe.input, mat.material) : 0;
//this allows pouring the ouput material back into the crucible
if(recipe != null && getQuantaFromType(recipe.output, mat.material) > 0) {
recipeAmount += mat.amount;
matchesRecipe = true;
continue;
}
if(recipeInputRequired == 0) {
//if this type isn't required by the recipe, add it to the waste stack
wasteAmount += mat.amount;
} else {
//the maximum is the recipe's ratio scaled up to the recipe stack's capacity
int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent;
int amountStored = getQuantaFromType(recipeStack, mat.material);
matchesRecipe = true;
recipeAmount += mat.amount;
//if the amount of that input would exceed the amount dictated by the recipe, return false
if(recipe != null && amountStored + mat.amount > matMaximum)
return false;
}
}
//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;
}
public void addToStack(List<MaterialStack> stack, MaterialStack matStack) {
for(MaterialStack mat : stack) {
if(mat.material == matStack.material) {
mat.amount += matStack.amount;
return;
}
}
stack.add(matStack.copy());
}
public CrucibleRecipe getLoadedRecipe() {
if(slots[0] != null && slots[0].getItem() == ModItems.crucible_template) {
return CrucibleRecipes.indexMapping.get(slots[0].getItemDamage());
}
return null;
}
/* "Arrays and Lists don't have a common ancestor" my fucking ass */
public int getQuantaFromType(MaterialStack[] stacks, NTMMaterial mat) {
for(MaterialStack stack : stacks) {
@ -493,7 +505,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
}
return 0;
}
public int getQuantaFromType(List<MaterialStack> stacks, NTMMaterial mat) {
int sum = 0;
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) {
return new GUICrucible(player.inventory, this);
}
AxisAlignedBB bb = null;
@Override
public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) {
bb = AxisAlignedBB.getBoundingBox(
xCoord - 1,
@ -538,10 +550,10 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
zCoord + 2
);
}
return bb;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() {
@ -550,30 +562,30 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
@Override
public boolean canAcceptPartialPour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
CrucibleRecipe recipe = getLoadedRecipe();
if(recipe == null) {
return getQuantaFromType(this.wasteStack, null) < this.wasteZCapacity;
}
int recipeContent = recipe.getInputAmount();
int recipeInputRequired = getQuantaFromType(recipe.input, stack.material);
int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent;
int amountStored = getQuantaFromType(recipeStack, stack.material);
return amountStored < matMaximum && getQuantaFromType(this.recipeStack, null) < this.recipeZCapacity;
}
@Override
public MaterialStack pour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
CrucibleRecipe recipe = getLoadedRecipe();
if(recipe == null) {
int amount = getQuantaFromType(this.wasteStack, null);
if(amount + stack.amount <= this.wasteZCapacity) {
this.addToStack(this.wasteStack, stack.copy());
return null;
@ -583,16 +595,16 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
return new MaterialStack(stack.material, stack.amount - toAdd);
}
}
int recipeContent = recipe.getInputAmount();
int recipeInputRequired = getQuantaFromType(recipe.input, stack.material);
int matMaximum = recipeInputRequired * this.recipeZCapacity / recipeContent;
if(recipeInputRequired + stack.amount <= matMaximum) {
this.addToStack(this.recipeStack, stack.copy());
return null;
}
int toAdd = matMaximum - stack.amount;
toAdd = Math.min(toAdd, this.recipeZCapacity - getQuantaFromType(this.recipeStack, null));
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;
public class TileEntityMachineRadiolysis extends TileEntityMachineBase implements IEnergyProviderMK2, IFluidStandardTransceiver, IGUIProvider, IInfoProviderEC, IFluidCopiable {
public long power;
public static final int maxPower = 1000000;
public int heat;
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_rtg = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
public TileEntityMachineRadiolysis() {
super(15); //10 rtg slots, 2 fluid ID slots (io), 2 irradiation slots (io), battery slot
tanks = new FluidTank[3];
@ -52,12 +52,12 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
tanks[1] = new FluidTank(Fluids.NONE, 2_000);
tanks[2] = new FluidTank(Fluids.NONE, 2_000);
}
@Override
public String getName() {
return "container.radiolysis";
}
/* IO Methods */
@Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
@ -68,32 +68,32 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
public int[] getAccessibleSlotsFromSide(int side) {
return slot_io;
}
@Override
public boolean canExtractItem(int i, ItemStack itemStack, int j) {
return (i < 10 && itemStack.getItem() instanceof ItemRTGPelletDepleted) || i == 13;
}
/* NBT Methods */
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.power = nbt.getLong("power");
this.heat = nbt.getInteger("heat");
tanks[0].readFromNBT(nbt, "input");
tanks[1].readFromNBT(nbt, "output1");
tanks[2].readFromNBT(nbt, "output2");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setLong("power", power);
nbt.setInteger("heat", heat);
tanks[0].writeToNBT(nbt, "input");
tanks[1].writeToNBT(nbt, "output1");
tanks[2].writeToNBT(nbt, "output2");
@ -101,29 +101,29 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
power = Library.chargeItemsFromTE(slots, 14, power, maxPower);
heat = RTGUtil.updateRTGs(slots, slot_rtg);
power += heat * 10;
if(power > maxPower)
power = maxPower;
tanks[0].setType(10, 11, slots);
setupTanks();
if(heat > 100) {
int crackTime = (int) Math.max(-0.1 * (heat - 100) + 30, 5);
if(worldObj.getTotalWorldTime() % crackTime == 0)
crack();
if(heat >= 200 && worldObj.getTotalWorldTime() % 100 == 0)
sterilize();
}
for(DirPos pos : getConPos()) {
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());
@ -150,9 +150,9 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
super.deserialize(buf);
this.power = buf.readLong();
this.heat = buf.readInt();
tanks[0].serialize(buf);
tanks[1].serialize(buf);
tanks[2].serialize(buf);
tanks[0].deserialize(buf);
tanks[1].deserialize(buf);
tanks[2].deserialize(buf);
}
protected DirPos[] getConPos() {
@ -163,17 +163,17 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
new DirPos(xCoord, yCoord, zCoord - 2, Library.NEG_Z)
};
}
/* Processing Methods */
private void crack() {
Pair<FluidStack, FluidStack> quart = RadiolysisRecipes.getRadiolysis(tanks[0].getTankType());
if(quart != null) {
int left = quart.getKey().fill;
int right = quart.getValue().fill;
if(tanks[0].getFill() >= 100 && hasSpace(left, right)) {
tanks[0].setFill(tanks[0].getFill() - 100);
tanks[1].setFill(tanks[1].getFill() + left);
@ -181,15 +181,15 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
}
}
}
private boolean hasSpace(int left, int right) {
return tanks[1].getFill() + left <= tanks[1].getMaxFill() && tanks[2].getFill() + right <= tanks[2].getMaxFill();
}
private void setupTanks() {
Pair<FluidStack, FluidStack> quart = RadiolysisRecipes.getRadiolysis(tanks[0].getTankType());
if(quart != null) {
tanks[1].setTankType(quart.getKey().type);
tanks[2].setTankType(quart.getValue().type);
@ -198,21 +198,21 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
tanks[1].setTankType(Fluids.NONE);
tanks[2].setTankType(Fluids.NONE);
}
}
// Code: pressure, sword, sterilize.
private void sterilize() {
if(slots[12] != null) {
if(slots[12].getItem() instanceof ItemFood && !(slots[12].getItem() == ModItems.pancake)) {
this.decrStackSize(12, 1);
}
if(!checkIfValid()) return;
ItemStack output = slots[12].copy();
output.stackSize = 1;
if(slots[13] == null) {
this.decrStackSize(12, output.stackSize);
slots[13] = output;
@ -232,14 +232,14 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
}
}
}
private boolean checkIfValid() {
if(slots[12] == null) return false;
if(!slots[12].hasTagCompound()) return false;
if(!slots[12].getTagCompound().getBoolean("ntmContagion")) return false;
return true;
}
/* Power methods */
@Override
public void setPower(long power) {
@ -255,7 +255,7 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
public long getMaxPower() {
return maxPower;
}
@Override
public FluidTank[] getAllTanks() {
return tanks;
@ -275,11 +275,11 @@ public class TileEntityMachineRadiolysis extends TileEntityMachineBase implement
public boolean canConnect(FluidType type, ForgeDirection dir) {
return dir != ForgeDirection.UNKNOWN && dir != ForgeDirection.DOWN;
}
public AxisAlignedBB getRenderBoundingBox() {
return AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord, zCoord - 1, xCoord + 2, yCoord + 3, zCoord + 2);
}
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() {
return 65536.0D;

View File

@ -81,7 +81,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
if(canProcess()) {
int minAmount = mold.getCost() * 9;
// Makes it flush the buffers after 10 seconds of inactivity
if(worldObj.getWorldTime() >= lastCastTick + 200) {
minAmount = mold.getCost();
@ -116,9 +116,10 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
lastCastTick = worldObj.getWorldTime();
}
}
}
sendStandard(150);
sendStandard(150);
}
}
@ -190,7 +191,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
}
return false;
}
}
@Override
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);
}
@Override public void serialize(ByteBuf buf) {
@Override
public void serialize(ByteBuf buf) {
water.serialize(buf);
steam.serialize(buf);
}
@Override public void deserialize(ByteBuf buf) {
@Override
public void deserialize(ByteBuf buf) {
water.deserialize(buf);
steam.deserialize(buf);
}
@ -341,7 +344,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
}
public boolean isLoaded = true;
@Override
public boolean isLoaded() {
return isLoaded;

View File

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

View File

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

View File

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

View File

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

View File

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