forked from mekanism/Mekanism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve/fix exposure of capabilities from transmitters so that they p…
…roperly don't expose a capability at all on a given side when the connection type is set to none mekanism#6708
- Loading branch information
1 parent
d68da7f
commit 66d4b4f
Showing
51 changed files
with
464 additions
and
421 deletions.
There are no files selected for viewing
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
45 changes: 45 additions & 0 deletions
45
src/main/java/mekanism/common/capabilities/DynamicHandler.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,45 @@ | ||
package mekanism.common.capabilities; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import mcp.MethodsReturnNonnullByDefault; | ||
import mekanism.api.IContentsListener; | ||
import mekanism.api.annotations.FieldsAreNonnullByDefault; | ||
import net.minecraft.util.Direction; | ||
|
||
@FieldsAreNonnullByDefault | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
public abstract class DynamicHandler<TANK> implements IContentsListener { | ||
|
||
protected final Function<Direction, List<TANK>> containerSupplier; | ||
protected final InteractPredicate canExtract; | ||
protected final InteractPredicate canInsert; | ||
@Nullable | ||
private final IContentsListener listener; | ||
|
||
protected DynamicHandler(Function<Direction, List<TANK>> containerSupplier, InteractPredicate canExtract, InteractPredicate canInsert, | ||
@Nullable IContentsListener listener) { | ||
this.containerSupplier = containerSupplier; | ||
this.canExtract = canExtract; | ||
this.canInsert = canInsert; | ||
this.listener = listener; | ||
} | ||
|
||
@Override | ||
public void onContentsChanged() { | ||
if (listener != null) { | ||
listener.onContentsChanged(); | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
public interface InteractPredicate { | ||
|
||
InteractPredicate ALWAYS_TRUE = (tank, side) -> true; | ||
|
||
boolean test(int tank, @Nullable Direction side); | ||
} | ||
} |
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
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
99 changes: 0 additions & 99 deletions
99
...in/java/mekanism/common/capabilities/chemical/transmitter/ChemicalTransmitterWrapper.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/main/java/mekanism/common/capabilities/energy/DynamicStrictEnergyHandler.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,43 @@ | ||
package mekanism.common.capabilities.energy; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import mcp.MethodsReturnNonnullByDefault; | ||
import mekanism.api.Action; | ||
import mekanism.api.IContentsListener; | ||
import mekanism.api.annotations.FieldsAreNonnullByDefault; | ||
import mekanism.api.energy.IEnergyContainer; | ||
import mekanism.api.energy.IMekanismStrictEnergyHandler; | ||
import mekanism.api.math.FloatingLong; | ||
import mekanism.common.capabilities.DynamicHandler; | ||
import net.minecraft.util.Direction; | ||
|
||
@FieldsAreNonnullByDefault | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
public class DynamicStrictEnergyHandler extends DynamicHandler<IEnergyContainer> implements IMekanismStrictEnergyHandler { | ||
|
||
public DynamicStrictEnergyHandler(Function<Direction, List<IEnergyContainer>> tankSupplier, InteractPredicate canExtract, InteractPredicate canInsert, | ||
@Nullable IContentsListener listener) { | ||
super(tankSupplier, canExtract, canInsert, listener); | ||
} | ||
|
||
@Override | ||
public List<IEnergyContainer> getEnergyContainers(@Nullable Direction side) { | ||
return containerSupplier.apply(side); | ||
} | ||
|
||
@Override | ||
public FloatingLong insertEnergy(int container, FloatingLong amount, @Nullable Direction side, Action action) { | ||
//If we can insert into the specific tank from that side, try to. Otherwise exit | ||
return canInsert.test(container, side) ? IMekanismStrictEnergyHandler.super.insertEnergy(container, amount, side, action) : amount; | ||
} | ||
|
||
@Override | ||
public FloatingLong extractEnergy(int container, FloatingLong amount, @Nullable Direction side, Action action) { | ||
//If we can extract from a specific tank from a given side, try to. Otherwise exit | ||
return canExtract.test(container, side) ? IMekanismStrictEnergyHandler.super.extractEnergy(container, amount, side, action) : FloatingLong.ZERO; | ||
} | ||
} |
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
Oops, something went wrong.