Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Unreleased - Minecraft 1.10.2

- Let Forge fluid sources control their own drainage, preserving the amount and fluid data they return.
- Keep fluid in the steam pump when an attached tank refuses it, and only charge for successful pickup.
- Pause the steam still when its output cannot hold a complete batch, without wasting input or processing steam.
- Let a loaded musket fire its last cartridge without needing spare ammunition in the inventory.
- Stop musket shots at terrain and select nearby targets without loading extra server chunks.
- Send machine sounds to connected nearby players without scanning unloaded chunks; keep the existing sound ranges and spectator exclusion.
- Read live redstone before the crusher and furnace resume after loading, preserving saved work and the first-tick steam heat bonus without changing the normal polling interval.
- Save real coal-boiler tank changes immediately, leave simulations unchanged, and return an empty result for null, empty or mismatched drain requests.
- Honour the water-only input of coal, electric and geothermal boilers even when empty, and safely refuse null, empty or mismatched fluid requests.
- Save accepted external tank changes in electric and geothermal boilers immediately, with the same simulation and client-side safeguards as the coal boiler.

Steam Advantage 2.2.5.110021

- Retain unfinished drill progress when rebuilding the mining target after a world or chunk reload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static float maxDelta(float newValue,float oldValue,float maxChange){

public static void drawNeedle(float pivotX, float pivotY, float zLevel,
float value) {
value = displayLevel(value);


final float pixelSize = 1.0f / 256; // conversion factor
Expand Down Expand Up @@ -84,6 +85,7 @@ public static void drawNeedle(float pivotX, float pivotY, float zLevel,
}

public static void drawFlameProgress(int x, int y, float flameHeight, GUIContainer gc){
flameHeight = displayLevel(flameHeight);
if(flameHeight <= 0) return;
final int flameTexX = 200;
final int flameTexY = 0;
Expand All @@ -99,6 +101,7 @@ public static void drawFlameProgress(int x, int y, float flameHeight, GUIContain
public static void drawFluidBar(FluidStack fs, float barHeight, int xPos, int yPos,
GUIContainer guiContainer, int x, int y, float z,
ResourceLocation displayImage, int texOverlayX, int texOverlayY, int texOverlayW, int texOverlayH){
barHeight = displayLevel(barHeight);
final int texMarginW = (texOverlayW - 16) / 2;
final int texMarginH = (texOverlayH - 60) / 2;
final int w = 16;
Expand All @@ -116,6 +119,7 @@ public static void drawFluidBar(FluidStack fs, float barHeight, int xPos, int yP

public static void drawDownArrowProgress(int x, int y, float progress,
GUIContainer gc) {
progress = displayLevel(progress);
if(progress <= 0) return;
final int arrowTexX = 184;
final int arrowTexY = 0;
Expand All @@ -127,4 +131,8 @@ public static void drawDownArrowProgress(int x, int y, float progress,
gc.drawTexturedModalRect(x, y, arrowTexX, arrowTexY, width, h);
}
}

static float displayLevel(float value) {
return Float.isFinite(value) ? Math.max(0F, Math.min(1F, value)) : 0F;
}
}
59 changes: 32 additions & 27 deletions src/main/java/zone/moddev/mc/steamadvantage/items/MusketItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static zone.moddev.mc.steamadvantage.util.SoundHelper.playSoundAtPosition;

import java.util.List;
import java.util.Optional;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -32,6 +33,7 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
Expand Down Expand Up @@ -104,7 +106,7 @@ public EnumAction getItemUseAction(ItemStack stack){
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack srcItemStack, World world, EntityPlayer playerEntity, EnumHand hand){
if(hand != EnumHand.MAIN_HAND) return ActionResult.newResult(EnumActionResult.PASS,srcItemStack);
if(!hasAmmo(playerEntity, srcItemStack)) return ActionResult.newResult(EnumActionResult.FAIL,srcItemStack);
if(isNotLoaded(srcItemStack) && !hasAmmo(playerEntity, srcItemStack)) return ActionResult.newResult(EnumActionResult.FAIL,srcItemStack);
if(isNotLoaded(srcItemStack) && EnchantmentHelper.getEnchantmentLevel(Enchantments.rapid_reload, srcItemStack) > 0){
// instant reload
decrementAmmo(playerEntity,srcItemStack);
Expand Down Expand Up @@ -364,37 +366,43 @@ public static void decrementAmmo(EntityLivingBase e, ItemStack musket) {


public static RayTraceResult rayTraceBlocksAndEntities(World w, double maxRange, EntityLivingBase source){
double rangeSqr = maxRange * maxRange;
Vec3d rayOrigin = new Vec3d(source.posX, source.posY + source.getEyeHeight(), source.posZ);
Vec3d rayDirection = source.getLookVec();
BlockPos srcPos = source.getPosition();
AxisAlignedBB aoi = new AxisAlignedBB(srcPos.getX() - maxRange, srcPos.getY() - maxRange, srcPos.getZ() - maxRange,
srcPos.getX() + maxRange, srcPos.getY() + maxRange, srcPos.getZ() + maxRange);
List<Entity> entities = w.getEntitiesWithinAABBExcludingEntity(source, aoi);
double closestDistSqr = Double.MAX_VALUE;
Vec3d rangeEnd = rayOrigin.add(rayDirection.scale(maxRange));
RayTraceResult terrainHit = w.rayTraceBlocks(rayOrigin, rangeEnd, true, false, false);
Vec3d rayEnd = terrainHit == null ? rangeEnd : terrainHit.hitVec;
AxisAlignedBB aoi = new AxisAlignedBB(
Math.min(rayOrigin.xCoord, rayEnd.xCoord) - 1, Math.min(rayOrigin.yCoord, rayEnd.yCoord) - 1, Math.min(rayOrigin.zCoord, rayEnd.zCoord) - 1,
Math.max(rayOrigin.xCoord, rayEnd.xCoord) + 1, Math.max(rayOrigin.yCoord, rayEnd.yCoord) + 1, Math.max(rayOrigin.zCoord, rayEnd.zCoord) + 1);
double closestDistSqr = rayOrigin.squareDistanceTo(rayEnd);
Entity closestEntity = null;
for(Entity e : entities){
double distSqr = e.getDistanceSq(source.posX, source.posY, source.posZ);
if(distSqr < rangeSqr){
// e is within range
AxisAlignedBB box = e.getEntityBoundingBox();
if(rayIntersectsBoundingBox(rayOrigin,rayDirection, box)){
// e is in cross-hairs
if(distSqr < closestDistSqr){
// e is closest entity in line of fire
closestDistSqr = distSqr;
closestEntity = e;
}
Vec3d closestHit = null;
// Target only loaded entities; a spatial query can otherwise load distant chunks.
for(Entity e : w.loadedEntityList){
if(e == source || e.isDead || !EntitySelectors.NOT_SPECTATING.apply(e)
|| !aoi.intersectsWith(e.getEntityBoundingBox())) continue;
Optional<Vec3d> hit = rayHitBeforeTerrain(rayOrigin, rayEnd, e.getEntityBoundingBox());
if(hit.isPresent()){
double distSqr = rayOrigin.squareDistanceTo(hit.get());
if(distSqr < closestDistSqr){
closestDistSqr = distSqr;
closestEntity = e;
closestHit = hit.get();
}
}
}
if(closestEntity == null) {
return w.rayTraceBlocks(rayOrigin, rayOrigin.add(mul(rayDirection, maxRange)), true, false, false);
return closestEntity == null ? terrainHit : new RayTraceResult(closestEntity, closestHit);
}

static Optional<Vec3d> rayHitBeforeTerrain(Vec3d origin, Vec3d terrainEnd, AxisAlignedBB target){
Vec3d point;
if(target.isVecInside(origin)){
point = origin;
} else {
Vec3d pos = new Vec3d(closestEntity.posX, closestEntity.posY+closestEntity.getEyeHeight(), closestEntity.posZ);
RayTraceResult entityCollision = new RayTraceResult(closestEntity, pos);
return entityCollision;
RayTraceResult hit = target.calculateIntercept(origin, terrainEnd);
point = hit == null ? null : hit.hitVec;
}
return Optional.ofNullable(point).filter(hit -> origin.squareDistanceTo(hit) < origin.squareDistanceTo(terrainEnd));
}

public static boolean rayIntersectsBoundingBox(Vec3d rayOrigin, Vec3d rayDirection, AxisAlignedBB box){
Expand Down Expand Up @@ -427,9 +435,6 @@ public static boolean rayIntersectsBoundingBox(Vec3d rayOrigin, Vec3d rayDirecti
}


private static Vec3d mul(Vec3d a, double b){
return new Vec3d(a.xCoord * b, a.yCoord * b, a.zCoord * b);
}
private static double max(double a, double b){
return Math.max(a, b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public class BlastFurnaceTileEntity extends cyano.poweradvantage.api.simple.Tile
private static final float minSmeltingTemperature = 100f;

private boolean redstone = true;
private boolean redstoneInitialized = false;

@Override
public void onLoad() {
super.onLoad();
redstoneInitialized = false;
}

public BlastFurnaceTileEntity() {
super(Power.steam_power, 200, "tile.steamadvantage.steam_furnace.name");
Expand Down Expand Up @@ -63,6 +70,10 @@ public float getTemperatureLevel(){
@Override
public void tickUpdate(boolean isServerWorld) {
if(isServerWorld){
if (!redstoneInitialized && getWorld() != null) {
redstone = hasRedstoneSignal();
redstoneInitialized = true;
}
// fual input heat
float e = 0;
if(burnTime > 0){
Expand Down Expand Up @@ -168,6 +179,7 @@ public void powerUpdate(){
this.sync();
}
redstone = hasRedstoneSignal();
redstoneInitialized = true;
}

private boolean hasRedstoneSignal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ public class CoalBoilerTileEntity extends cyano.poweradvantage.api.simple.TileEn

public CoalBoilerTileEntity() {
super(new ConduitType[]{Power.steam_power,Fluids.fluidConduit_general}, new float[]{1000,1000}, "tile.steamadvantage.steam_boiler_coal.name");
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 4);
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 4) {
@Override
protected void onContentsChanged() {
if (CoalBoilerTileEntity.this.getWorld() != null
&& !CoalBoilerTileEntity.this.getWorld().isRemote) {
CoalBoilerTileEntity.this.markDirty();
}
}
};
inventory = new ItemStack[1];
}

Expand Down Expand Up @@ -350,6 +358,8 @@ && getTank().getFluidAmount() > 0
*/
@Override
public int fill(EnumFacing face, FluidStack fluid, boolean forReal) {
if (fluid == null || fluid.amount <= 0 || !canFill(face, fluid.getFluid())
|| getTank().getFluidAmount() >= getTank().getCapacity()) return 0;
if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){
return getTank().fill(fluid, forReal);
} else {
Expand All @@ -364,10 +374,11 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) {
*/
@Override
public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) {
if (fluid == null || fluid.amount <= 0) return null;
if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){
return getTank().drain(fluid.amount,forReal);
} else {
return new FluidStack(getTank().getFluid().getFluid(),0);
return null;
}
}
/**
Expand All @@ -378,6 +389,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) {
*/
@Override
public FluidStack drain(EnumFacing face, int amount, boolean forReal) {
if (amount <= 0) return null;
if(getTank().getFluidAmount() > 0 ){
return getTank().drain(amount,forReal);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ public ElectricBoilerTileEntity() {
super(new ConduitType[]{Power.steam_power, ELECTRIC_POWER, Fluids.fluidConduit_general},
new float[]{100, MAX_ELECTRICITY, 1000},
"tile.steamadvantage.steam_boiler_electric.name");
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 2);
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 2) {
@Override
protected void onContentsChanged() {
if (ElectricBoilerTileEntity.this.getWorld() != null
&& !ElectricBoilerTileEntity.this.getWorld().isRemote) {
ElectricBoilerTileEntity.this.markDirty();
}
}
};
inventory = new ItemStack[0];
}

Expand Down Expand Up @@ -302,6 +310,8 @@ public PowerRequest getPowerRequest(ConduitType offer) {
*/
@Override
public int fill(EnumFacing face, FluidStack fluid, boolean forReal) {
if (fluid == null || fluid.amount <= 0 || !canFill(face, fluid.getFluid())
|| getTank().getFluidAmount() >= getTank().getCapacity()) return 0;
if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){
return getTank().fill(fluid, forReal);
} else {
Expand All @@ -316,10 +326,11 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) {
*/
@Override
public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) {
if (fluid == null || fluid.amount <= 0) return null;
if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){
return getTank().drain(fluid.amount,forReal);
} else {
return new FluidStack(getTank().getFluid().getFluid(),0);
return null;
}
}
/**
Expand All @@ -330,6 +341,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) {
*/
@Override
public FluidStack drain(EnumFacing face, int amount, boolean forReal) {
if (amount <= 0) return null;
if(getTank().getFluidAmount() > 0 ){
return getTank().drain(amount,forReal);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ public class GeothermalBoilerTileEntity extends cyano.poweradvantage.api.simple.

public GeothermalBoilerTileEntity() {
super(new ConduitType[]{Power.steam_power,Fluids.fluidConduit_general}, new float[]{100,1000}, "tile.steamadvantage.steam_boiler_geothermal.name");
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 2);
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 2) {
@Override
protected void onContentsChanged() {
if (GeothermalBoilerTileEntity.this.getWorld() != null
&& !GeothermalBoilerTileEntity.this.getWorld().isRemote) {
GeothermalBoilerTileEntity.this.markDirty();
}
}
};
inventory = new ItemStack[0];
}

Expand Down Expand Up @@ -331,6 +339,8 @@ public PowerRequest getPowerRequest(ConduitType offer) {
*/
@Override
public int fill(EnumFacing face, FluidStack fluid, boolean forReal) {
if (fluid == null || fluid.amount <= 0 || !canFill(face, fluid.getFluid())
|| getTank().getFluidAmount() >= getTank().getCapacity()) return 0;
if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){
return getTank().fill(fluid, forReal);
} else {
Expand All @@ -345,10 +355,11 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) {
*/
@Override
public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) {
if (fluid == null || fluid.amount <= 0) return null;
if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){
return getTank().drain(fluid.amount,forReal);
} else {
return new FluidStack(getTank().getFluid().getFluid(),0);
return null;
}
}
/**
Expand All @@ -359,6 +370,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) {
*/
@Override
public FluidStack drain(EnumFacing face, int amount, boolean forReal) {
if (amount <= 0) return null;
if(getTank().getFluidAmount() > 0 ){
return getTank().drain(amount,forReal);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public RockCrusherTileEntity() {
}

private boolean redstone = true;
private boolean redstoneInitialized = false;

@Override
public void onLoad() {
super.onLoad();
redstoneInitialized = false;
}


private int timeSinceLastSteamBurst = 0;
Expand All @@ -41,6 +48,10 @@ public RockCrusherTileEntity() {
@Override
public void tickUpdate(boolean isServerWorld) {
if(isServerWorld){
if (!redstoneInitialized && getWorld() != null) {
redstone = hasRedstoneSignal();
redstoneInitialized = true;
}
// reset progress when item in slot changes
ItemStack input = inventory[0];
if(itemCheck != null && ItemStack.areItemsEqual(itemCheck, input) == false){
Expand Down Expand Up @@ -112,6 +123,7 @@ public void powerUpdate(){
super.powerUpdate();

redstone = hasRedstoneSignal();
redstoneInitialized = true;

if(oldSteam != this.getEnergy(Power.steam_power) || progress != oldProgress){
this.sync();
Expand Down
Loading
Loading