generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02609eb
commit 07f9876
Showing
10 changed files
with
201 additions
and
6 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/8202586f691eec5ad0bb88d13a278951d0c130fb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.21.1 2024-09-13T13:43:18.3815776 Languages: en_us for mod: justdirethings | ||
a4ea5c922b56481d51520c57e5bed3dc238465e4 assets/justdirethings/lang/en_us.json | ||
// 1.21.1 2024-09-13T13:53:01.5331943 Languages: en_us for mod: justdirethings | ||
50598341120df2f850d5821435699dff7b3dcdb3 assets/justdirethings/lang/en_us.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...ain/java/com/direwolf20/justdirethings/common/capabilities/ExperienceHolderFluidTank.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.direwolf20.justdirethings.common.capabilities; | ||
|
||
import com.direwolf20.justdirethings.common.blockentities.ExperienceHolderBE; | ||
import com.direwolf20.justdirethings.setup.Registration; | ||
import net.neoforged.neoforge.fluids.FluidStack; | ||
import net.neoforged.neoforge.fluids.capability.templates.FluidTank; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class ExperienceHolderFluidTank extends FluidTank { | ||
private final ExperienceHolderBE experienceHolderBE; | ||
|
||
public ExperienceHolderFluidTank(ExperienceHolderBE experienceHolderBE, Predicate<FluidStack> validator) { | ||
super(Integer.MAX_VALUE, validator); | ||
this.experienceHolderBE = experienceHolderBE; | ||
fluid = new FluidStack(Registration.XP_FLUID_SOURCE.get(), getFluidAmount()); | ||
} | ||
|
||
public int getFluidAmount() { | ||
// Prevent overflow by capping experienceHolderBE.exp at Integer.MAX_VALUE / 20 | ||
if (experienceHolderBE.exp > Integer.MAX_VALUE / 20) { | ||
return Integer.MAX_VALUE; // If multiplying by 20 would overflow, return max int value | ||
} | ||
|
||
// Safe to multiply without overflow | ||
return Math.min(experienceHolderBE.exp * 20, getCapacity()); | ||
} | ||
|
||
public int getCapacity() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public int fill(FluidStack resource, FluidAction action) { | ||
if (resource.isEmpty() || !isFluidValid(resource)) { | ||
return 0; | ||
} | ||
if (action.simulate()) { | ||
if (fluid.isEmpty()) { | ||
return Math.min(capacity, resource.getAmount() - resource.getAmount() % 20); | ||
} | ||
if (!FluidStack.isSameFluidSameComponents(fluid, resource)) { | ||
return 0; | ||
} | ||
return Math.min(capacity - getFluidAmount() - ((capacity - getFluidAmount()) % 20), resource.getAmount() - resource.getAmount() % 20); | ||
} | ||
if (fluid.isEmpty()) { | ||
return resource.getAmount() - insertFluid(resource.getAmount()); | ||
} | ||
if (!FluidStack.isSameFluidSameComponents(fluid, resource)) { | ||
return 0; | ||
} | ||
int filled = resource.getAmount() - insertFluid(resource.getAmount()); | ||
if (filled > 0) | ||
onContentsChanged(); | ||
return filled; | ||
} | ||
|
||
public int insertFluid(int amt) { | ||
int remaining = experienceHolderBE.addExp(amt / 20); | ||
int excessFluid = amt % 20; // Calculate remainder fluid (less than 1 XP) | ||
return (remaining * 20) + excessFluid; | ||
} | ||
|
||
public int extractFluid(int amt) { | ||
int expNeeded = amt / 20; | ||
int unAvailable = experienceHolderBE.subExp(expNeeded); | ||
return (unAvailable * 20) + (amt % 20); | ||
} | ||
|
||
@Override | ||
public FluidStack drain(FluidStack resource, FluidAction action) { | ||
if (resource.isEmpty() || !FluidStack.isSameFluidSameComponents(resource, fluid)) { | ||
return FluidStack.EMPTY; | ||
} | ||
return drain(resource.getAmount(), action); | ||
} | ||
|
||
@Override | ||
public FluidStack drain(int maxDrain, FluidAction action) { | ||
int drained = maxDrain - (maxDrain % 20); //Trim remainder | ||
if (getFluidAmount() < drained) { | ||
drained = getFluidAmount(); | ||
} | ||
FluidStack stack = fluid.copyWithAmount(drained); | ||
if (action.execute() && drained > 0) { | ||
extractFluid(drained); | ||
onContentsChanged(); | ||
} | ||
return stack; | ||
} | ||
|
||
@Override | ||
protected void onContentsChanged() { | ||
experienceHolderBE.markDirtyClient(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.19 KB
src/main/resources/assets/justdirethings/textures/gui/buttons/pullfluids.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.19 KB
src/main/resources/assets/justdirethings/textures/gui/buttons/pushfluids.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.