Added some nice text in the controller screen.

Added 'minAir' key into the PNRC recipe
This commit is contained in:
Quarris
2022-11-11 16:43:00 +00:00
parent 8fc86a433f
commit 7164ddb87f
12 changed files with 213 additions and 51 deletions

View File

@@ -21,7 +21,7 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'
version = '1.16.5-0.1.66-B' + getVersionNumber()
version = '1.16.5-0.1.67-B' + getVersionNumber()
group = 'com.ticticboooom.mods.mm' // 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.

View File

@@ -20,16 +20,16 @@ public class ControllerBlockContainer extends Container {
public ControllerBlockContainer(@Nullable ContainerType<?> p_i50105_1_, int windowId, PlayerInventory inv, ControllerBlockEntity tile) {
super(p_i50105_1_, windowId);
this.tile = tile;
int playerOffsetX = 8;
int playerOffsetY = 121;
int playerOffsetX = 7;
int playerOffsetY = 140;
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 9; i++) {
this.addSlot(new Slot(inv, 9 + (j * 9 + i), i* 18 + playerOffsetX, j* 18 + playerOffsetY));
this.addSlot(new Slot(inv, 9 + (j * 9 + i), i * 18 + playerOffsetX, j * 18 + playerOffsetY));
}
}
for (int i = 0; i < 9; i++) {
this.addSlot(new Slot(inv, i,8 + (i * 18), 179));
this.addSlot(new Slot(inv, i, 7 + (i * 18), 198));
}
}
@@ -38,7 +38,6 @@ public class ControllerBlockContainer extends Container {
}
@Override
public boolean canInteractWith(PlayerEntity p_75145_1_) {
return true;

View File

@@ -3,6 +3,7 @@ package com.ticticboooom.mods.mm.block.tile;
import com.ticticboooom.mods.mm.block.container.ControllerBlockContainer;
import com.ticticboooom.mods.mm.data.MachineProcessRecipe;
import com.ticticboooom.mods.mm.data.MachineStructureRecipe;
import com.ticticboooom.mods.mm.model.ControllerDisplayData;
import com.ticticboooom.mods.mm.model.ProcessUpdate;
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
import com.ticticboooom.mods.mm.registration.RecipeTypes;
@@ -34,6 +35,9 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
@Getter
private ProcessUpdate processData = new ProcessUpdate();
@Getter
private ControllerDisplayData displayData = new ControllerDisplayData();
public ControllerBlockEntity(RegistryObject<TileEntityType<?>> type, RegistryObject<ContainerType<ControllerBlockContainer>> container, String controllerId) {
super(type.get());
this.container = container;
@@ -45,45 +49,49 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
if (world.isRemote()) {
return;
}
processData.setMsg("Failed to construct \nthe machine");
List<MachineStructureRecipe> structures = world.getRecipeManager().getRecipesForType(RecipeTypes.MACHINE_STRUCTURE);
processData.setMsg("");
boolean foundStructure = false;
// Check if the controller has a structure attached to itself
if (processData.getStructureDefinition().getStructure() != null) {
MachineStructureRecipe structure = processData.getStructureDefinition().getStructure();
int transformIndex = processData.getStructureDefinition().getTransformIndex();
// Check if the structure is still matched in the world
if (structure.matchesSpecificTransform(this.pos, world, transformIndex)) {
processData.setMsg("Found structure");
processData.setStatus("Working");
onStructureFound(structure, transformIndex);
foundStructure = true;
} else {
// If the structure is no longer matched, invalidate the current recipe
invalidateRecipe();
}
}
// If the structure does not exist, attempt to find one that does
List<MachineStructureRecipe> structures = world.getRecipeManager().getRecipesForType(RecipeTypes.MACHINE_STRUCTURE);
if (!foundStructure) {
for (MachineStructureRecipe structure : structures) {
int index = structure.matchesAnyTransform(this.pos, world, controllerId);
if (index != -1) {
if (!structure.equals(processData.getStructureDefinition().getStructure())) {
processData.setTicksTaken(0);
}
processData.getStructureDefinition().setStructure(structure);
processData.getStructureDefinition().setTransformIndex(index);
processData.setMsg("Found structure");
processData.setStatus("Working");
onStructureFound(structure, index);
foundStructure = true;
break;
}
}
}
update();
// If no structure was found at all, invalidate the recipe.
if (!foundStructure) {
invalidateRecipe();
processData.setStatus("Invalid Machine");
processData.setTicksTaken(0);
processData.getStructureDefinition().setStructure(null);
processData.setRecipe(null);
}
update();
}
private void onStructureFound(MachineStructureRecipe structure, int index) {
@@ -114,36 +122,34 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
// Maybe instead of checking all recipe again first check if our current recipe is still valid?
if (processData.getRecipe() != null && processData.getRecipe().matches(inputPorts, structure.getStructureId(), processData)) {
processData.getRecipe().process(inputPorts, outputPorts, processData);
processed = true;
return;
}
if (!processed) {
// If we havent processed the previous recipe that means it needs to be invalidated
invalidateRecipe();
for (MachineProcessRecipe recipe : processRecipes) {
if (recipe.matches(inputPorts, structure.getStructureId(), processData)) {
// TODO Make sure the recipe doesn't stop progress when some inputs aren't present
if (!recipe.equals(processData.getRecipe())) {
if (processData.getRecipe() != null) {
processData.getRecipe().onInterrupted(inputPorts, outputPorts);
}
processData.setTicksTaken(0);
// If we haven't processed the previous recipe that means it needs to be invalidated
for (MachineProcessRecipe recipe : processRecipes) {
if (recipe.matches(inputPorts, structure.getStructureId(), processData)) {
// TODO Make sure the recipe doesn't stop progress when some inputs aren't present
if (!recipe.equals(processData.getRecipe())) {
if (processData.getRecipe() != null) {
processData.getRecipe().onInterrupted(inputPorts, outputPorts);
}
processData.setRecipe(recipe);
recipe.process(inputPorts, outputPorts, processData);
processed = true;
break;
//processData.setTicksTaken(0);
}
processData.setRecipe(recipe);
recipe.process(inputPorts, outputPorts, processData);
processed = true;
break;
}
}
if (!processed) {
this.processData.setRecipe(null);
this.processData.setTicksTaken(0);
invalidateRecipe();
}
}
public void invalidateRecipe() {
processData.setStatus("Idle");
if (processData.getStructureDefinition().getStructure() != null && processData.getRecipe() != null) {
processData.getRecipe().onInterrupted(processData.getStructureDefinition().getInputPorts(), processData.getStructureDefinition().getOutputPorts());
}
@@ -162,8 +168,10 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
@Override
public CompoundNBT write(CompoundNBT nbt) {
this.displayData.fromProcess(this.processData);
nbt.putInt("ticks", processData.getTicksTaken());
nbt.putString("msg", processData.getMsg());
nbt.put("DisplayData", this.displayData.serialize());
return super.write(nbt);
}
@@ -172,5 +180,6 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
super.read(p_230337_1_, nbt);
processData.setTicksTaken(nbt.getInt("ticks"));
processData.setMsg(nbt.getString("msg"));
this.displayData.deserialize(nbt.getCompound("DisplayData"));
}
}

View File

@@ -3,9 +3,13 @@ package com.ticticboooom.mods.mm.client.screen;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.ticticboooom.mods.mm.MM;
import com.ticticboooom.mods.mm.block.container.ControllerBlockContainer;
import com.ticticboooom.mods.mm.data.MachineStructureRecipe;
import com.ticticboooom.mods.mm.model.ControllerDisplayData;
import com.ticticboooom.mods.mm.model.ProcessUpdate;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.util.text.ITextComponent;
public class ControllerBlockContainerScreen extends ContainerScreen<ControllerBlockContainer> {
@@ -18,6 +22,13 @@ public class ControllerBlockContainerScreen extends ContainerScreen<ControllerBl
private static final ResourceLocation GUI = new ResourceLocation(MM.ID, "textures/gui/gui_large.png");
@Override
protected void init() {
this.xSize = 174;
this.ySize = 222;
super.init();
}
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, float p_230430_4_) {
super.render(stack, mouseX, mouseY, p_230430_4_);
@@ -27,19 +38,53 @@ public class ControllerBlockContainerScreen extends ContainerScreen<ControllerBl
@Override
protected void drawGuiContainerForegroundLayer(MatrixStack stack, int x0, int y0) {
this.minecraft.fontRenderer.func_238418_a_(container.getTile().getDisplayName(), 10, -10, 176, 0xfefefe);
drawString(stack, this.minecraft.fontRenderer, "Inventory", 7, 110, 0xfefefe);
int y = 50;
for (String s : container.getTile().getProcessData().getMsg().split("\n")) {
drawString(stack, this.minecraft.fontRenderer, s, 12, y, 0xfefefe);
y += 12;
//this.minecraft.fontRenderer.func_238418_a_(container.getTile().getDisplayName(), 10, -10, 176, 0xfefefe);
ControllerDisplayData data = container.getTile().getDisplayData();
// Structure Name
String structureName = "Unknown Structure";
if (!StringUtils.isNullOrEmpty(data.getStructureName())) {
structureName = data.getStructureName();
}
drawCenteredString(stack, this.minecraft.fontRenderer, structureName, this.xSize / 2, 10, 0xfefefe);
int baseInfoY = 56;
int infoOffset = 0;
// Recipe Name
if (!StringUtils.isNullOrEmpty(data.getRecipeName())) {
String recipeName = data.getRecipeName();
drawString(stack, this.font, "Recipe: " + recipeName, 10, baseInfoY + (this.font.FONT_HEIGHT + 2) * infoOffset, 0xfefefe);
infoOffset++;
}
// Status
String status = "Unknown";
if (!StringUtils.isNullOrEmpty(data.getStatus())) {
status = data.getStatus();
}
drawString(stack, this.font, "Status: " + status, 10, baseInfoY + (this.font.FONT_HEIGHT + 2) * infoOffset, 0xfefefe);
infoOffset++;
// Progress
if (!StringUtils.isNullOrEmpty(data.getProgress())) {
String progress = data.getProgress();
drawString(stack, this.font, "Progress: " + progress, 10, baseInfoY + (this.font.FONT_HEIGHT + 2) * infoOffset, 0xfefefe);
infoOffset++;
}
// Message
int y = baseInfoY + (this.font.FONT_HEIGHT + 2) * infoOffset;
for (String s : data.getMessage().split("\n")) {
drawString(stack, this.font, s, 11, y, 0xfefefe);
y += this.font.FONT_HEIGHT + 2;
}
drawString(stack, this.font, this.playerInventory.getDisplayName(), 6, 129, 0xfefefe);
}
@Override
protected void drawGuiContainerBackgroundLayer(MatrixStack stack, float partialTicks, int x, int y) {
this.renderBackground(stack);
this.minecraft.textureManager.bindTexture(GUI);
this.blit(stack, this.guiLeft, this.guiTop - 20, 0, 0, 256, 256);
this.blit(stack, this.guiLeft, this.guiTop, 0, 0, 256, 256);
}
}

View File

@@ -21,6 +21,7 @@ import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.world.World;
import javax.annotation.Nullable;
@@ -39,12 +40,15 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
@Getter
private final String structureId;
private final ResourceLocation rl;
@Getter
private final String name;
private final List<Double> inputRolls = new ArrayList<>();
private final List<Double> outputRolls = new ArrayList<>();
private final Random rand = new Random();
public MachineProcessRecipe(List<PortState> inputs, List<PortState> outputs, int ticks, String structureId, ResourceLocation rl) {
public MachineProcessRecipe(String name, List<PortState> inputs, List<PortState> outputs, int ticks, String structureId, ResourceLocation rl) {
this.name = name;
this.inputs = inputs;
this.outputs = outputs;
this.ticks = ticks;
@@ -52,6 +56,10 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
this.rl = rl;
}
public boolean hasName() {
return !StringUtils.isNullOrEmpty(this.name);
}
public boolean matches(List<PortStorage> inputPorts, String structureId, ProcessUpdate update) {
return structureId.equals(this.structureId) && canTake(inputPorts, update.getTakenIndices());
}
@@ -195,8 +203,7 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
}
update.setTicksTaken(update.getTicksTaken() + 1);
}
update.setMsg((int) (((float) update.getTicksTaken() / (float) ticks) * 100) + "%");
return;
//update.setMsg((int) (((float) update.getTicksTaken() / (float) ticks) * 100) + "%");
}
@Override
@@ -249,6 +256,10 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
@Override
public MachineProcessRecipe read(ResourceLocation rl, JsonObject obj) {
try {
String name = null;
if (obj.has("name")) {
name = obj.get("name").getAsString();
}
int ticks = obj.get("ticks").getAsInt();
String structureId = obj.get("structureId").getAsString();
JsonArray inputs = obj.get("inputs").getAsJsonArray();
@@ -258,7 +269,7 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
List<PortState> outputStates = getStates(outputs);
validateProcess(inputStates, outputStates, ticks, structureId, rl);
MM.LOG.debug("Added process '{}' for structure '{}'", rl, structureId);
return new MachineProcessRecipe(inputStates, outputStates, ticks, structureId, rl);
return new MachineProcessRecipe(name, inputStates, outputStates, ticks, structureId, rl);
} catch (InvalidProcessDefinitionException e) {
MM.LOG.error("InvalidProcessDefinition: " + e.getMessage());
}
@@ -307,13 +318,17 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
@Nullable
@Override
public MachineProcessRecipe read(ResourceLocation rl, PacketBuffer buf) {
String name = null;
if (buf.readBoolean()) {
name = buf.readString();
}
int inputCount = buf.readInt();
int outputCount = buf.readInt();
int ticks = buf.readInt();
String structureId = buf.readString();
List<PortState> inputs = getStates(buf, inputCount);
List<PortState> outputs = getStates(buf, outputCount);
return new MachineProcessRecipe(inputs, outputs, ticks, structureId, rl);
return new MachineProcessRecipe(name, inputs, outputs, ticks, structureId, rl);
}
private List<PortState> getStates(PacketBuffer buf, int count) {
@@ -333,6 +348,11 @@ public class MachineProcessRecipe implements IRecipe<IInventory> {
@Override
public void write(PacketBuffer buf, MachineProcessRecipe recipe) {
boolean hasName = recipe.hasName();
buf.writeBoolean(hasName);
if (hasName) {
buf.writeString(recipe.name);
}
buf.writeInt(recipe.inputs.size());
buf.writeInt(recipe.outputs.size());
buf.writeInt(recipe.ticks);

View File

@@ -0,0 +1,54 @@
package com.ticticboooom.mods.mm.model;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.nbt.CompoundNBT;
@Setter
@Getter
public class ControllerDisplayData {
private String structureName;
private String recipeName;
private String status;
private String progress;
private String message;
public void fromProcess(ProcessUpdate process) {
this.structureName = "";
if (process.getStructureDefinition().getStructure() != null) {
this.structureName = process.getStructureDefinition().getStructure().getName();
}
this.recipeName = "";
if (process.getRecipe() != null && process.getRecipe().hasName()) {
this.recipeName = process.getRecipe().getName();
}
this.status = process.getStatus();
this.progress = "";
if (process.getRecipe() != null) {
float percentage = ((float) process.getTicksTaken() / (float) process.getRecipe().getTicks()) * 100;
this.progress = String.format("%d/%d (%.2f%%)", process.getTicksTaken(), process.getRecipe().getTicks(), percentage);
}
this.message = process.getMsg();
}
public CompoundNBT serialize() {
CompoundNBT nbt = new CompoundNBT();
nbt.putString("StructureName", this.structureName);
nbt.putString("RecipeName", this.recipeName);
nbt.putString("Status", this.status);
nbt.putString("Progress", this.progress);
nbt.putString("Message", this.message);
return nbt;
}
public void deserialize(CompoundNBT nbt) {
this.structureName = nbt.getString("StructureName");
this.recipeName = nbt.getString("RecipeName");
this.status = nbt.getString("Status");
this.progress = nbt.getString("Progress");
this.message = nbt.getString("Message");
}
}

View File

@@ -11,6 +11,7 @@ import java.util.List;
@Setter
public class ProcessUpdate {
private int ticksTaken;
private String status = "";
private String msg = "";
private MachineProcessRecipe recipe;
private WorldStructureDefinition structureDefinition = new WorldStructureDefinition();

View File

@@ -17,16 +17,20 @@ import mezz.jei.api.ingredients.IIngredientType;
import net.minecraft.util.ResourceLocation;
import java.util.List;
import java.util.Optional;
public class PneumaticPortState extends PortState {
public static final Codec<PneumaticPortState> CODEC = RecordCodecBuilder.create(x -> x.group(
Codec.FLOAT.optionalFieldOf("minAir").forGetter(z -> Optional.of(z.minPressure)),
Codec.FLOAT.fieldOf("air").forGetter(z -> z.pressure)
).apply(x, PneumaticPortState::new));
).apply(x, (min, pressure) -> new PneumaticPortState(min.orElse(pressure), pressure)));
private float minPressure;
private float pressure;
public PneumaticPortState(float pressure) {
public PneumaticPortState(float minPressure, float pressure) {
this.minPressure = minPressure;
this.pressure = pressure;
}
@@ -44,7 +48,7 @@ public class PneumaticPortState extends PortState {
public boolean validateRequirement(List<PortStorage> storage) {
for (PortStorage portStorage : storage) {
if (portStorage instanceof PneumaticPortStorage){
if (((PneumaticPortStorage) portStorage).getInv().getAir() >= this.pressure){
if (((PneumaticPortStorage) portStorage).getInv().getAir() >= this.minPressure){
return true;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -0,0 +1,26 @@
{
"type": "masterfulmachinery:machine_process",
"structureId": "test_all",
"controllerId": "basic",
"name": "Test Name",
"ticks": 100,
"inputs": [
{
"type": "masterfulmachinery:pncr_pressure",
"consumeInstantly": true,
"perTick": true,
"data": {
"air": 14000
}
}
],
"outputs":[
{
"type": "masterfulmachinery:items",
"data": {
"item": "minecraft:nether_star",
"count": 1
}
}
]
}

View File

@@ -5,7 +5,8 @@
"name": "Testing All The Ports",
"layout": [
[
")C*",
"vCv",
") *",
"+ ,",
"- .",
"/ 0",
@@ -18,6 +19,9 @@
]
],
"legend": {
"v": {
"block": "minecraft:stone"
},
")": {
"block": "masterfulmachinery:basic_simple_port_items_output"
},

View File

@@ -1,2 +1,2 @@
#Sat Aug 13 15:30:13 UTC 2022
VERSION_CODE=1041
#Fri Nov 11 16:38:22 UTC 2022
VERSION_CODE=1092