mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-03-18 21:40:34 +01:00
fixed create port and added infuse types to mek support
This commit is contained in:
@@ -20,7 +20,7 @@ apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
version = '1.16.5-0.1.41-B' + getVersionNumber()
|
||||
version = '1.16.5-0.1.42-B' + getVersionNumber()
|
||||
group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = 'MasterfulMachinery'
|
||||
java.toolchain.languageVersion = JavaLanguageVersion.of(8) // Mojang ships Java 8 to end users, so your mod should target Java 8.
|
||||
|
||||
@@ -54,26 +54,29 @@ public class RotationGenMachinePortBlockEntity extends GeneratingKineticTileEnti
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
this.reActivateSource = true;
|
||||
super.tick();
|
||||
if (storage instanceof RotationPortStorage) {
|
||||
RotationPortStorage stor = (RotationPortStorage) this.storage;
|
||||
float speed = stor.getSpeed();
|
||||
if (speed != this.speed) {
|
||||
if (!hasSource()) {
|
||||
effects.queueRotationIndicators();
|
||||
}
|
||||
applyNewSpeed(this.speed, speed);
|
||||
}
|
||||
if (hasNetwork() && speed != 0) {
|
||||
KineticNetwork network = getOrCreateNetwork();
|
||||
notifyStressCapacityChange(calculateAddedStressCapacity());
|
||||
getOrCreateNetwork().updateCapacityFor(this, calculateStressApplied());
|
||||
network.updateStress();
|
||||
}
|
||||
|
||||
onSpeedChanged(this.speed);
|
||||
sendData();
|
||||
}
|
||||
this.storage.tick(this);
|
||||
// if (storage instanceof RotationPortStorage) {
|
||||
// RotationPortStorage stor = (RotationPortStorage) this.storage;
|
||||
// float prev = this.speed;
|
||||
// float speed = stor.getSpeed();
|
||||
// if (speed != prev) {
|
||||
// if (!hasSource()) {
|
||||
// effects.queueRotationIndicators();
|
||||
// }
|
||||
// applyNewSpeed(prev, speed);
|
||||
// }
|
||||
// if (hasNetwork() && speed != 0) {
|
||||
// KineticNetwork network = getOrCreateNetwork();
|
||||
// notifyStressCapacityChange(calculateAddedStressCapacity());
|
||||
// getOrCreateNetwork().updateCapacityFor(this, calculateStressApplied());
|
||||
// network.updateStress();
|
||||
// }
|
||||
//
|
||||
// onSpeedChanged(prev);
|
||||
// sendData();
|
||||
// }
|
||||
|
||||
if (!world.isRemote()) {
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.ALL.noArg(), new TileClientUpdatePacket.Data(pos, write(new CompoundNBT())));
|
||||
|
||||
@@ -62,7 +62,7 @@ public class RotationMachinePortBlockEntity extends KineticTileEntity implements
|
||||
if (storage instanceof RotationPortStorage) {
|
||||
RotationPortStorage storage = (RotationPortStorage) this.storage;
|
||||
if (input) {
|
||||
storage.setSpeed(getSpeed());
|
||||
storage.setSpeed(Math.abs(getSpeed()));
|
||||
}
|
||||
}
|
||||
if (!world.isRemote()) {
|
||||
|
||||
@@ -32,9 +32,10 @@ public class MMLangProvider extends LanguageProvider {
|
||||
}
|
||||
|
||||
}
|
||||
// this.add(MMSetup.BLUEPRINT.get(), "Blueprint");
|
||||
// this.add(MMSetup.STRUCTURE_DEVICE.get(), "Structure Scanner");
|
||||
// this.add(MMSetup.PROJECTOR_BLOCK.get(), "Structure Projector");
|
||||
// this.add(MMSetup.STRUCTURE_BLOCK.get(), "Structure Scanner");
|
||||
this.add(MMSetup.BLUEPRINT.get(), "Blueprint");
|
||||
this.add(MMSetup.STRUCTURE_DEVICE.get(), "Structure Scanner");
|
||||
this.add(MMSetup.PROJECTOR_BLOCK.get(), "Structure Projector");
|
||||
this.add(MMSetup.STRUCTURE_BLOCK.get(), "Structure Scanner");
|
||||
this.add("container.masterfulmachinery.create_rotation", "Rotation Port");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.ticticboooom.mods.mm.inventory.mek;
|
||||
|
||||
import mekanism.api.Action;
|
||||
import mekanism.api.chemical.Chemical;
|
||||
import mekanism.api.chemical.ChemicalStack;
|
||||
import mekanism.api.chemical.IChemicalHandler;
|
||||
import mekanism.api.chemical.IChemicalTank;
|
||||
import mekanism.api.chemical.gas.GasStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MekChemicalInventory<CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> implements IChemicalHandler<CHEMICAL, STACK>, IChemicalTank<CHEMICAL, STACK> {
|
||||
private STACK stack;
|
||||
private STACK empty;
|
||||
private BiFunction<CHEMICAL, Long, STACK> factory;
|
||||
private long capacity;
|
||||
|
||||
public MekChemicalInventory(STACK empty, long capacity, BiFunction<CHEMICAL, Long, STACK> factory) {
|
||||
this.stack = (STACK) empty.copy();
|
||||
this.capacity = capacity;
|
||||
this.empty = empty;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public STACK getChemicalInTank(int i) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChemicalInTank(int i, STACK stack) {
|
||||
if (i == 0){
|
||||
this.stack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTankCapacity(int i) {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int i, STACK stack) {
|
||||
if (i != 0){
|
||||
return false;
|
||||
}
|
||||
return this.stack.isEmpty() || stack.getType() == this.stack.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public STACK insertChemical(int i, STACK stack, Action action) {
|
||||
if (!isValid(i, stack)) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
if (action.simulate()) {
|
||||
if (this.stack.getAmount() + stack.getAmount() > capacity) {
|
||||
return factory.apply(stack.getType(), (this.stack.getAmount() + stack.getAmount() - capacity));
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.stack.getAmount() + stack.getAmount() > capacity) {
|
||||
long preAmount = this.stack.getAmount();
|
||||
if (this.stack.isEmpty()){
|
||||
this.stack = factory.apply(stack.getType(), capacity);
|
||||
} else {
|
||||
this.stack.setAmount(capacity);
|
||||
}
|
||||
return factory.apply(stack.getType(), (preAmount + stack.getAmount() - capacity));
|
||||
} else {
|
||||
if (this.stack.isEmpty()) {
|
||||
this.stack = factory.apply(stack.getType(), stack.getAmount());
|
||||
} else {
|
||||
this.stack.setAmount(this.stack.getAmount() + stack.getAmount());
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public STACK extractChemical(int i, long l, Action action) {
|
||||
if (action.simulate()) {
|
||||
if (stack.getAmount() - l < 0) {
|
||||
return factory.apply(stack.getType(), l - (l + stack.getAmount()));
|
||||
} else {
|
||||
return factory.apply(stack.getType(), l);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getAmount() - l < 0) {
|
||||
long preAmount = stack.getAmount();
|
||||
this.stack = empty;
|
||||
return factory.apply(stack.getType(),l - (preAmount - l));
|
||||
} else {
|
||||
stack.setAmount(stack.getAmount() - l);
|
||||
return factory.apply(stack.getType(), l);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public STACK getEmptyStack() {
|
||||
return empty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public STACK createStack(STACK stack, long l) {
|
||||
return factory.apply(stack.getType(), l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public STACK getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(STACK stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackUnchecked(STACK stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(STACK stack) {
|
||||
return isValid(0, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentsChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundNBT nbt) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,129 +1,11 @@
|
||||
package com.ticticboooom.mods.mm.inventory.mek;
|
||||
|
||||
import mekanism.api.Action;
|
||||
import mekanism.api.chemical.gas.Gas;
|
||||
import mekanism.api.chemical.gas.GasStack;
|
||||
import mekanism.api.chemical.gas.IGasHandler;
|
||||
import mekanism.api.chemical.gas.IGasTank;
|
||||
|
||||
public class PortMekGasInventory implements IGasHandler, IGasTank {
|
||||
private GasStack stack = GasStack.EMPTY;
|
||||
private long capacity;
|
||||
public class PortMekGasInventory extends MekChemicalInventory<Gas, GasStack> {
|
||||
|
||||
public PortMekGasInventory(long capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasStack getChemicalInTank(int i) {
|
||||
return i == 0 ? stack : GasStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChemicalInTank(int i, GasStack stack) {
|
||||
if (i == 0) {
|
||||
this.stack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTankCapacity(int i) {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int i, GasStack stack) {
|
||||
if (i != 0){
|
||||
return false;
|
||||
}
|
||||
return this.stack.isEmpty() || stack.getType() == this.stack.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasStack insertChemical(int i, GasStack stack, Action action) {
|
||||
if (!isValid(i, stack)) {
|
||||
return GasStack.EMPTY;
|
||||
}
|
||||
|
||||
if (action.simulate()) {
|
||||
if (this.stack.getAmount() + stack.getAmount() > capacity) {
|
||||
return new GasStack(stack.getType(), (this.stack.getAmount() + stack.getAmount() - capacity));
|
||||
} else {
|
||||
return GasStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.stack.getAmount() + stack.getAmount() > capacity) {
|
||||
long preAmount = this.stack.getAmount();
|
||||
if (this.stack.isEmpty()){
|
||||
this.stack = new GasStack(stack.getType(), capacity);
|
||||
} else {
|
||||
this.stack.setAmount(capacity);
|
||||
}
|
||||
return new GasStack(stack.getType(), (preAmount + stack.getAmount() - capacity));
|
||||
} else {
|
||||
if (this.stack.isEmpty()) {
|
||||
this.stack = new GasStack(stack.getType(), stack.getAmount());
|
||||
} else {
|
||||
this.stack.setAmount(this.stack.getAmount() + stack.getAmount());
|
||||
}
|
||||
return GasStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GasStack extractChemical(int i, long l, Action action) {
|
||||
if (action.simulate()) {
|
||||
if (stack.getAmount() - l < 0) {
|
||||
return new GasStack(stack.getType(), l - (l + stack.getAmount()));
|
||||
} else {
|
||||
return new GasStack(stack.getType(), l);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getAmount() - l < 0) {
|
||||
long preAmount = stack.getAmount();
|
||||
this.stack = GasStack.EMPTY;
|
||||
return new GasStack(stack.getType(),l - (preAmount - l));
|
||||
} else {
|
||||
stack.setAmount(stack.getAmount() - l);
|
||||
return new GasStack(stack.getType(), l);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(GasStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackUnchecked(GasStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(GasStack stack) {
|
||||
return isValid(0, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentsChanged() {
|
||||
|
||||
super(GasStack.EMPTY, capacity, GasStack::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.ticticboooom.mods.mm.inventory.mek;
|
||||
|
||||
import mekanism.api.chemical.infuse.InfuseType;
|
||||
import mekanism.api.chemical.infuse.InfusionStack;
|
||||
|
||||
public class PortMekInfuseInventory extends MekChemicalInventory<InfuseType, InfusionStack> {
|
||||
|
||||
public PortMekInfuseInventory(long capacity) {
|
||||
super(InfusionStack.EMPTY, capacity, InfusionStack::new);
|
||||
}
|
||||
}
|
||||
@@ -6,130 +6,13 @@ import mekanism.api.chemical.gas.IGasHandler;
|
||||
import mekanism.api.chemical.gas.IGasTank;
|
||||
import mekanism.api.chemical.slurry.ISlurryHandler;
|
||||
import mekanism.api.chemical.slurry.ISlurryTank;
|
||||
import mekanism.api.chemical.slurry.Slurry;
|
||||
import mekanism.api.chemical.slurry.SlurryStack;
|
||||
|
||||
public class PortMekSlurryInventory implements ISlurryHandler, ISlurryTank {
|
||||
private SlurryStack stack = SlurryStack.EMPTY;
|
||||
private long capacity;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class PortMekSlurryInventory extends MekChemicalInventory<Slurry, SlurryStack> {
|
||||
public PortMekSlurryInventory(long capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlurryStack getChemicalInTank(int i) {
|
||||
return i == 0 ? stack : SlurryStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChemicalInTank(int i, SlurryStack stack) {
|
||||
if (i == 0) {
|
||||
this.stack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTankCapacity(int i) {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int i, SlurryStack stack) {
|
||||
if (i != 0){
|
||||
return false;
|
||||
}
|
||||
return this.stack.isEmpty() || stack.getType() == this.stack.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlurryStack insertChemical(int i, SlurryStack stack, Action action) {
|
||||
if (!isValid(i, stack)) {
|
||||
return SlurryStack.EMPTY;
|
||||
}
|
||||
if (action.simulate()) {
|
||||
if (this.stack.getAmount() + stack.getAmount() > capacity) {
|
||||
return new SlurryStack(stack.getType(), this.stack.getAmount() + stack.getAmount() - capacity);
|
||||
} else {
|
||||
return SlurryStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.stack.getAmount() + stack.getAmount() > capacity) {
|
||||
long preAmount = this.stack.getAmount();
|
||||
if (this.stack.isEmpty()){
|
||||
this.stack = new SlurryStack(stack.getType(), capacity);
|
||||
} else {
|
||||
this.stack.setAmount(capacity);
|
||||
}
|
||||
return new SlurryStack(stack.getType(), preAmount + stack.getAmount() - capacity);
|
||||
} else {
|
||||
if (this.stack.isEmpty()) {
|
||||
this.stack = new SlurryStack(stack.getType(), this.stack.getAmount() + stack.getAmount());
|
||||
} else {
|
||||
this.stack.setAmount(this.stack.getAmount() + stack.getAmount());
|
||||
}
|
||||
return SlurryStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SlurryStack extractChemical(int i, long l, Action action) {
|
||||
if (!isValid(i, stack)) {
|
||||
return SlurryStack.EMPTY;
|
||||
}
|
||||
|
||||
if (action.simulate()) {
|
||||
if (stack.getAmount() - l < 0) {
|
||||
return new SlurryStack(stack.getType(), l - (l + stack.getAmount() - capacity));
|
||||
} else {
|
||||
return new SlurryStack(stack.getType(), l);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getAmount() - l < 0) {
|
||||
long preAmount = stack.getAmount();
|
||||
this.stack = SlurryStack.EMPTY;
|
||||
return new SlurryStack(stack.getType(), l - (l + preAmount - capacity));
|
||||
} else {
|
||||
stack.setAmount(stack.getAmount() - l);
|
||||
return new SlurryStack(stack.getType(), l);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlurryStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(SlurryStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackUnchecked(SlurryStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(SlurryStack stack) {
|
||||
return isValid(0, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentsChanged() {
|
||||
|
||||
super(SlurryStack.EMPTY, capacity, SlurryStack::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.ticticboooom.mods.mm.ports.parser;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.ports.state.MekInfusePortState;
|
||||
import com.ticticboooom.mods.mm.ports.state.MekSlurryPortState;
|
||||
import com.ticticboooom.mods.mm.ports.state.PortState;
|
||||
import com.ticticboooom.mods.mm.ports.storage.MekInfusePortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.MekSlurryPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import lombok.SneakyThrows;
|
||||
import mekanism.api.chemical.slurry.SlurryStack;
|
||||
import mekanism.client.jei.MekanismJEI;
|
||||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MekInfusePortParser extends PortFactory {
|
||||
|
||||
@Override
|
||||
public void setIngredients(IIngredients ingredients, List<?> stacks, boolean input) {
|
||||
if (input) {
|
||||
ingredients.setInputs(MekanismJEI.TYPE_SLURRY, (List<SlurryStack>)stacks);
|
||||
} else {
|
||||
ingredients.setOutputs(MekanismJEI.TYPE_SLURRY, (List<SlurryStack>)stacks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PortState createState(JsonObject obj) {
|
||||
DataResult<Pair<MekInfusePortState, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(MekInfusePortState.CODEC).apply(obj);
|
||||
return apply.result().get().getFirst();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public PortState createState(PacketBuffer buf) {
|
||||
return buf.func_240628_a_(MekInfusePortState.CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<PortStorage> createStorage(JsonObject obj) {
|
||||
return () -> {
|
||||
DataResult<Pair<MekInfusePortStorage, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(MekInfusePortStorage.CODEC).apply(obj);
|
||||
return apply.result().get().getFirst();
|
||||
};
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void write(PacketBuffer buf, PortState state) {
|
||||
buf.func_240629_a_(MekInfusePortState.CODEC, (MekInfusePortState)state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getInputOverlay() {
|
||||
return new ResourceLocation(MM.ID, "block/compat_ports/mekanism_slurry_cutout");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getOutputOverlay() {
|
||||
return new ResourceLocation(MM.ID, "block/compat_ports/mekanism_slurry_cutout");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.ticticboooom.mods.mm.ports.state;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.exception.InvalidProcessDefinitionException;
|
||||
import com.ticticboooom.mods.mm.helper.RLUtils;
|
||||
import com.ticticboooom.mods.mm.ports.storage.MekInfusePortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.MekSlurryPortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import lombok.SneakyThrows;
|
||||
import mekanism.api.Action;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.chemical.infuse.InfusionStack;
|
||||
import mekanism.api.chemical.slurry.SlurryStack;
|
||||
import mekanism.client.jei.ChemicalStackRenderer;
|
||||
import mekanism.client.jei.MekanismJEI;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.gui.drawable.IDrawableStatic;
|
||||
import mezz.jei.api.gui.ingredient.IGuiIngredientGroup;
|
||||
import mezz.jei.api.helpers.IJeiHelpers;
|
||||
import mezz.jei.api.ingredients.IIngredientType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MekInfusePortState extends PortState {
|
||||
|
||||
public static final Codec<MekInfusePortState> CODEC = RecordCodecBuilder.create(x -> x.group(
|
||||
Codec.STRING.fieldOf("infuse").forGetter(z -> z.infuse),
|
||||
Codec.LONG.fieldOf("amount").forGetter(z -> z.amount)
|
||||
).apply(x, MekInfusePortState::new));
|
||||
|
||||
private final String infuse;
|
||||
private final long amount;
|
||||
|
||||
public MekInfusePortState(String gas, long amount) {
|
||||
this.infuse = gas;
|
||||
this.amount = amount;
|
||||
renderer = new ChemicalStackRenderer<>(amount, false, 16, 16, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processRequirement(List<PortStorage> storage) {
|
||||
long current = amount;
|
||||
for (PortStorage st : storage) {
|
||||
if (st instanceof MekSlurryPortStorage) {
|
||||
MekInfusePortStorage gasStorage = (MekInfusePortStorage) st;
|
||||
if (gasStorage.getInv().getStack().getType().getRegistryName().toString().equals(infuse)) {
|
||||
InfusionStack extract = gasStorage.getInv().extractChemical(0, current, Action.EXECUTE);
|
||||
current -= extract.getAmount();
|
||||
}
|
||||
if (current <= 0){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateRequirement(List<PortStorage> storage) {
|
||||
long current = amount;
|
||||
for (PortStorage st : storage) {
|
||||
if (st instanceof MekInfusePortStorage) {
|
||||
MekInfusePortStorage gasStorage = (MekInfusePortStorage) st;
|
||||
if (gasStorage.getInv().getStack().getType().getRegistryName().toString().equals(infuse)) {
|
||||
InfusionStack extract = gasStorage.getInv().extractChemical(0, current, Action.SIMULATE);
|
||||
current -= extract.getAmount();
|
||||
}
|
||||
if (current <= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processResult(List<PortStorage> storage) {
|
||||
long current = amount;
|
||||
for (PortStorage st : storage) {
|
||||
if (st instanceof MekInfusePortStorage) {
|
||||
MekInfusePortStorage gasStorage = (MekInfusePortStorage) st;
|
||||
InfusionStack extract = gasStorage.getInv().insertChemical(new InfusionStack(Objects.requireNonNull(MekanismAPI.infuseTypeRegistry().getValue(RLUtils.toRL(infuse))), current), Action.EXECUTE);
|
||||
current -= extract.getAmount();
|
||||
if (current <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateResult(List<PortStorage> storage) {
|
||||
long current = amount;
|
||||
for (PortStorage st : storage) {
|
||||
if (st instanceof MekInfusePortStorage) {
|
||||
MekInfusePortStorage gasStorage = (MekInfusePortStorage) st;
|
||||
InfusionStack extract = gasStorage.getInv().insertChemical(new InfusionStack(Objects.requireNonNull(MekanismAPI.infuseTypeRegistry().getValue(RLUtils.toRL(infuse))), current), Action.SIMULATE);
|
||||
current -= extract.getAmount();
|
||||
if (current <= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return new ResourceLocation(MM.ID, "mekanism_infuse");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void validateDefinition() {
|
||||
if (!RLUtils.isRL(infuse)){
|
||||
throw new InvalidProcessDefinitionException("Slurry: " + infuse + " is not a valid slurry id (ResourceLocation)");
|
||||
}
|
||||
|
||||
if (!MekanismAPI.slurryRegistry().containsKey(RLUtils.toRL(infuse))){
|
||||
throw new InvalidProcessDefinitionException("Slurry: " + infuse + " does not exist in the mekansim slurry registry");
|
||||
}
|
||||
}
|
||||
|
||||
private final ChemicalStackRenderer<SlurryStack> renderer;
|
||||
@Override
|
||||
public void render(MatrixStack ms, int x, int y, int mouseX, int mouseY, IJeiHelpers helpers) {
|
||||
IDrawableStatic drawable = helpers.getGuiHelper().getSlotDrawable();
|
||||
drawable.draw(ms, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupRecipe(IRecipeLayout layout, Integer typeIndex, int x, int y, boolean input) {
|
||||
IGuiIngredientGroup<SlurryStack> gasGroup = layout.getIngredientsGroup(MekanismJEI.TYPE_SLURRY);
|
||||
gasGroup.init(typeIndex, input, renderer, x + 1, y + 1, 16, 16, 0, 0);
|
||||
gasGroup.set(typeIndex, new SlurryStack(MekanismAPI.slurryRegistry().getValue(RLUtils.toRL(infuse)), amount));
|
||||
if (this.getChance() < 1) {
|
||||
gasGroup.addTooltipCallback((s, a, b, c) -> {
|
||||
if (s == typeIndex) {
|
||||
c.add(new StringTextComponent("Chance: " + this.getChance() * 100 + "%"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> getIngredient(boolean input) {
|
||||
return (List<T>) ImmutableList.of(new InfusionStack(MekanismAPI.infuseTypeRegistry().getValue(RLUtils.toRL(infuse)), amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredientType<?> getJeiIngredientType() {
|
||||
return MekanismJEI.TYPE_SLURRY;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,6 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.helper.RLUtils;
|
||||
import com.ticticboooom.mods.mm.inventory.mek.PortMekGasInventory;
|
||||
import lombok.Getter;
|
||||
@@ -15,8 +13,6 @@ import mekanism.common.capabilities.Capabilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.ticticboooom.mods.mm.ports.storage;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.helper.RLUtils;
|
||||
import com.ticticboooom.mods.mm.inventory.mek.PortMekInfuseInventory;
|
||||
import com.ticticboooom.mods.mm.inventory.mek.PortMekSlurryInventory;
|
||||
import lombok.Getter;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.chemical.infuse.InfusionStack;
|
||||
import mekanism.api.chemical.slurry.SlurryStack;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class MekInfusePortStorage extends PortStorage {
|
||||
public static final Codec<MekInfusePortStorage> CODEC = RecordCodecBuilder.create(x -> x.group(
|
||||
Codec.LONG.fieldOf("capacity").forGetter(z -> z.capacity)
|
||||
).apply(x, MekInfusePortStorage::new));
|
||||
|
||||
@Getter
|
||||
private final PortMekInfuseInventory inv;
|
||||
private long capacity;
|
||||
private final LazyOptional<PortMekInfuseInventory> invLO;
|
||||
|
||||
|
||||
public MekInfusePortStorage(long capacity) {
|
||||
inv = new PortMekInfuseInventory(capacity);
|
||||
this.capacity = capacity;
|
||||
invLO = LazyOptional.of(() -> inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getLO() {
|
||||
return invLO.cast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean validate(Capability<T> cap) {
|
||||
return cap == Capabilities.SLURRY_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT save(CompoundNBT nbt) {
|
||||
nbt.putString("infuse", inv.getStack().getType().getRegistryName().toString());
|
||||
nbt.putLong("amount", inv.getStack().getAmount());
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundNBT nbt) {
|
||||
if (nbt.contains("infuse")){
|
||||
inv.setStack(new InfusionStack(Objects.requireNonNull(MekanismAPI.infuseTypeRegistry().getValue(RLUtils.toRL(nbt.getString("infuse")))), nbt.getLong("amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen) {
|
||||
Minecraft.getInstance().textureManager.bindTexture(new ResourceLocation(MM.ID, "textures/gui/port_gui.png"));
|
||||
screen.blit(stack, left, top, 0, 0, 175, 256);
|
||||
int barOffsetX = 175 - 30;
|
||||
int barOffsetY = 20;
|
||||
screen.blit(stack, left + barOffsetX, top + barOffsetY, 175, 18, 18, 108);
|
||||
float amount = 0;
|
||||
if (inv.getStack().getAmount() > 0) {
|
||||
amount = (float) inv.getStack().getAmount() / inv.getTankCapacity(0);
|
||||
}
|
||||
screen.blit(stack, left + barOffsetX, top + barOffsetY, 193, 18, 18, (int) (108 * amount));
|
||||
AbstractGui.drawString(stack, Minecraft.getInstance().fontRenderer, inv.getStack().getType().getTextComponent().getString(), left + 30, top + 60, 0xfefefe);
|
||||
AbstractGui.drawString(stack, Minecraft.getInstance().fontRenderer, inv.getStack().getAmount() + "mB", left + 30, top + 80, 0xfefefe);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.ticticboooom.mods.mm.helper.RLUtils;
|
||||
import com.ticticboooom.mods.mm.inventory.mek.PortMekSlurryInventory;
|
||||
import lombok.Getter;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.chemical.infuse.InfuseType;
|
||||
import mekanism.api.chemical.slurry.SlurryStack;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.tile.IMachinePortTile;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import lombok.Getter;
|
||||
import me.desht.pneumaticcraft.api.PNCCapabilities;
|
||||
@@ -14,6 +15,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -88,8 +90,8 @@ public class PneumaticPortStorage extends PortStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(MachinePortBlockEntity tile) {
|
||||
this.inv.tick(tile);
|
||||
public void tick(IMachinePortTile tile) {
|
||||
this.inv.tick((TileEntity) tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class PortStorage {
|
||||
}
|
||||
};
|
||||
|
||||
public void tick(MachinePortBlockEntity tile) {
|
||||
public void tick(IMachinePortTile tile) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.contraptions.KineticNetwork;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.tile.IMachinePortTile;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -82,6 +83,7 @@ public class RotationPortStorage extends PortStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(MachinePortBlockEntity tile) {
|
||||
public void tick(IMachinePortTile tile) {
|
||||
this.speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class MMPorts {
|
||||
if (ModList.get().isLoaded("mekanism")) {
|
||||
PORTS.put(new ResourceLocation(MM.ID, "mekanism_gas"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_gas"), new MekGasPortParser()));
|
||||
PORTS.put(new ResourceLocation(MM.ID, "mekanism_slurry"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_slurry"), new MekSlurryPortParser()));
|
||||
PORTS.put(new ResourceLocation(MM.ID, "mekanism_infuse"),new MasterfulPortType(new ResourceLocation(MM.ID, "mekanism_infuse"), new MekInfusePortParser()));
|
||||
}
|
||||
if (ModList.get().isLoaded("pneumaticcraft")){
|
||||
PORTS.put(new ResourceLocation(MM.ID, "pncr_pressure"),new MasterfulPortType(new ResourceLocation(MM.ID, "pncr_pressure"), new PneumaticPortParser()));
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#Tue May 25 00:48:05 BST 2021
|
||||
VERSION_CODE=154
|
||||
#Tue May 25 07:36:11 BST 2021
|
||||
VERSION_CODE=171
|
||||
|
||||
Reference in New Issue
Block a user