Skip to content

Commit

Permalink
fixes (#246)
Browse files Browse the repository at this point in the history
* fix oven hatch rendering + auto output

* Update MachineRenderer.java

* fix ingredient copy + fast gtrecipe copy

* fix bolt name

* parallel searching
  • Loading branch information
Yefancy authored Aug 1, 2023
1 parent 3514d21 commit f646830
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.gregtechceu.gtceu.api.recipe.content.ContentModifier;
import com.gregtechceu.gtceu.api.recipe.content.SerializerIngredient;
import com.gregtechceu.gtceu.api.recipe.ingredient.SizedIngredient;
import com.gregtechceu.gtceu.core.mixins.IngredientAccessor;
import net.minecraft.world.item.crafting.Ingredient;

import java.util.Arrays;
Expand All @@ -26,10 +25,7 @@ public Ingredient copyInner(Ingredient content) {
if (content instanceof SizedIngredient sizedIngredient) {
return SizedIngredient.copy(sizedIngredient);
}
if (content.getClass() == Ingredient.class) {
return IngredientAccessor.create(Arrays.stream(((IngredientAccessor) content).getValues()));
}
return super.copyInner(content);
return SizedIngredient.create(content, 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ default boolean canShared() {
*/
List<IRecipeHandlerTrait> getRecipeHandlers();

/**
* whether its base model can be replaced by controller when it is formed.
*/
default boolean replacePartModelWhenFormed() {
return true;
}

/**
* get part's Appearance. same as IForgeBlock.getAppearance() / IFabricBlock.getAppearance()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public ManagedFieldHolder getFieldHolder() {
@Override
public List<FluidStack> handleRecipeInner(IO io, GTRecipe recipe, List<FluidStack> left, @Nullable String slotName, boolean simulate) {
if (io != this.handlerIO) return left;
var lastStatus = simulate ? Arrays.stream(storages).map(FluidStorage::serializeNBT).toArray(CompoundTag[]::new) : null;
for (FluidStorage capability : storages) {
var capabilities = simulate ? Arrays.stream(storages).map(FluidStorage::copy).toArray(FluidStorage[]::new) : storages;
for (FluidStorage capability : capabilities) {
Iterator<FluidStack> iterator = left.iterator();
if (io == IO.IN) {
while (iterator.hasNext()) {
Expand Down Expand Up @@ -133,14 +133,6 @@ public List<FluidStack> handleRecipeInner(IO io, GTRecipe recipe, List<FluidStac
}
if (left.isEmpty()) break;
}
if (lastStatus != null) {
for (int i = 0; i < storages.length; i++) {
var lastOnChange = storages[i].getOnContentsChanged();
storages[i].setOnContentsChanged(() -> {});
storages[i].deserializeNBT(lastStatus[i]);
storages[i].setOnContentsChanged(lastOnChange);
}
}
return left.isEmpty() ? null : left;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* @author KilaBash
Expand Down Expand Up @@ -79,9 +77,8 @@ public ManagedFieldHolder getFieldHolder() {
@Override
public List<Ingredient> handleRecipeInner(IO io, GTRecipe recipe, List<Ingredient> left, @Nullable String slotName, boolean simulate) {
if (io != this.handlerIO) return left;
var capability = storage;
var capability = simulate ? storage.copy() : storage;
Iterator<Ingredient> iterator = left.iterator();
var lastStatus = simulate ? storage.serializeNBT() : null;
if (io == IO.IN) {
while (iterator.hasNext()) {
Ingredient ingredient = iterator.next();
Expand Down Expand Up @@ -120,12 +117,6 @@ public List<Ingredient> handleRecipeInner(IO io, GTRecipe recipe, List<Ingredien
if (output.isEmpty()) iterator.remove();
}
}
if (lastStatus != null) {
var lastOnChange = storage.getOnContentsChanged();
storage.setOnContentsChanged(() -> {});
storage.deserializeNBT(lastStatus);
storage.setOnContentsChanged(lastOnChange);
}
return left.isEmpty() ? null : left;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
import com.gregtechceu.gtceu.api.recipe.content.Content;
import com.gregtechceu.gtceu.api.recipe.content.ContentModifier;
import io.netty.buffer.Unpooled;
import lombok.Getter;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Tuple;
Expand Down Expand Up @@ -61,10 +59,24 @@ public GTRecipe(GTRecipeType recipeType, ResourceLocation id, Map<RecipeCapabili
this.isFuel = isFuel;
}

public Map<RecipeCapability<?>, List<Content>> copyContents(Map<RecipeCapability<?>, List<Content>> contents) {
Map<RecipeCapability<?>, List<Content>> copyContents = new HashMap<>();
for (var entry : contents.entrySet()) {
var contentList = entry.getValue();
var cap = entry.getKey();
if (contentList != null && !contentList.isEmpty()) {
List<Content> contentsCopy = new ArrayList<>();
for (Content content : contentList) {
contentsCopy.add(content.copy(cap));
}
copyContents.put(entry.getKey(), contentsCopy);
}
}
return copyContents;
}

public GTRecipe copy() {
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
GTRecipeSerializer.SERIALIZER.toNetwork(buf, this);
return GTRecipeSerializer.SERIALIZER.fromNetwork(id, buf);
return new GTRecipe(recipeType, id, copyContents(inputs), copyContents(outputs), copyContents(tickInputs), copyContents(tickOutputs), conditions, data, duration, isFuel);
}

public GTRecipe copy(ContentModifier modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.io.InputStream;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;

/**
* @author KilaBash
Expand Down Expand Up @@ -210,18 +211,14 @@ public List<GTRecipe> searchFuelRecipe(RecipeManager recipeManager, IRecipeCapab

public List<GTRecipe> searchRecipe(RecipeManager recipeManager, IRecipeCapabilityHolder holder) {
if (!holder.hasProxies()) return Collections.emptyList();
List<GTRecipe> matches = new ArrayList<>();
for (var recipe : recipeManager.getAllRecipesFor(this)) {
if (!recipe.isFuel && recipe.matchRecipe(holder).isSuccess() && recipe.matchTickRecipe(holder).isSuccess()) {
matches.add(recipe);
}
}
List<GTRecipe> matches = recipeManager.getAllRecipesFor(this).parallelStream()
.filter(recipe -> !recipe.isFuel && recipe.matchRecipe(holder).isSuccess() && recipe.matchTickRecipe(holder).isSuccess())
.collect(Collectors.toList());
for (List<GTRecipe> recipes : proxyRecipes.values()) {
for (GTRecipe recipe : recipes) {
if (!recipe.isFuel && recipe.matchRecipe(holder).isSuccess() && recipe.matchTickRecipe(holder).isSuccess()) {
matches.add(recipe);
}
}
var found = recipes.parallelStream()
.filter(recipe -> !recipe.isFuel && recipe.matchRecipe(holder).isSuccess() && recipe.matchTickRecipe(holder).isSuccess())
.toList();
matches.addAll(found);
}
return matches;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.recipe.content;

import com.gregtechceu.gtceu.api.capability.recipe.RecipeCapability;
import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture;
import com.lowdragmc.lowdraglib.utils.LocalizationUtils;
import com.mojang.blaze3d.systems.RenderSystem;
Expand Down Expand Up @@ -32,6 +33,10 @@ public Object getContent() {
return content;
}

public Content copy(RecipeCapability<?> capability) {
return new Content(capability.copyContent(content), chance, tierChanceBoost, slotName, uiName);
}

public IGuiTexture createOverlay(boolean perTick) {
return new IGuiTexture() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void renderBaseModel(List<BakedQuad> quads, MachineDefinition definition,
*/
@Environment(EnvType.CLIENT)
public void renderMachine(List<BakedQuad> quads, MachineDefinition definition, @Nullable MetaMachine machine, Direction frontFacing, @Nullable Direction side, RandomSource rand, @Nullable Direction modelFacing, ModelState modelState) {
if (!(machine instanceof IMultiPart part) || !renderReplacedPartMachine(quads, part, frontFacing, side, rand, modelFacing, modelState)) {
if (!(machine instanceof IMultiPart part) || !part.replacePartModelWhenFormed() || !renderReplacedPartMachine(quads, part, frontFacing, side, rand, modelFacing, modelState)) {
renderBaseModel(quads, definition, machine, frontFacing, side, rand);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static void generateTools() {
SHAPE_EXTRUDERS[1] = SHAPE_EXTRUDER_ROD = REGISTRATE.item("rod_extruder_mold", Item::new)
.lang("Extruder Mold (Rod)").onRegister(materialInfo(new ItemMaterialInfo(new MaterialStack(GTMaterials.Steel, GTValues.M * 4)))).register();
SHAPE_EXTRUDERS[2] = SHAPE_EXTRUDER_BOLT = REGISTRATE.item("bolt_extruder_mold", Item::new)
.lang("Extruder Mold (Bold)").onRegister(materialInfo(new ItemMaterialInfo(new MaterialStack(GTMaterials.Steel, GTValues.M * 4)))).register();
.lang("Extruder Mold (Bolt)").onRegister(materialInfo(new ItemMaterialInfo(new MaterialStack(GTMaterials.Steel, GTValues.M * 4)))).register();
SHAPE_EXTRUDERS[3] = SHAPE_EXTRUDER_RING = REGISTRATE.item("ring_extruder_mold", Item::new)
.lang("Extruder Mold (Ring)").onRegister(materialInfo(new ItemMaterialInfo(new MaterialStack(GTMaterials.Steel, GTValues.M * 4)))).register();
SHAPE_EXTRUDERS[4] = SHAPE_EXTRUDER_CELL = REGISTRATE.item("cell_extruder_mold", Item::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.gregtechceu.gtceu.api.machine.trait.FluidTankProxyTrait;
import com.gregtechceu.gtceu.api.machine.trait.ItemHandlerProxyTrait;
import com.gregtechceu.gtceu.common.machine.multiblock.primitive.CokeOvenMachine;
import com.lowdragmc.lowdraglib.misc.ItemTransferList;
import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper;
import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper;
import com.lowdragmc.lowdraglib.syncdata.ISubscription;
Expand All @@ -34,17 +33,18 @@
public class CokeOvenHatch extends MultiblockPartMachine {
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(CokeOvenHatch.class, MultiblockPartMachine.MANAGED_FIELD_HOLDER);

public final ItemHandlerProxyTrait inventory;
public final ItemHandlerProxyTrait inputInventory, outputInventory;
public final FluidTankProxyTrait tank;
@Nullable
protected TickableSubscription autoIOSubs;
@Nullable
protected ISubscription inventorySubs, tankSubs;
protected ISubscription outputInventorySubs, outputTankSubs;


public CokeOvenHatch(IMachineBlockEntity holder, Object... args) {
super(holder);
this.inventory = new ItemHandlerProxyTrait(this, IO.BOTH);
this.inputInventory = new ItemHandlerProxyTrait(this, IO.IN);
this.outputInventory = new ItemHandlerProxyTrait(this, IO.OUT);
this.tank = new FluidTankProxyTrait(this, IO.BOTH);
}

Expand All @@ -59,41 +59,44 @@ public ManagedFieldHolder getFieldHolder() {
@Override
public void onUnload() {
super.onUnload();
inventory.setProxy(null);
inputInventory.setProxy(null);
outputInventory.setProxy(null);
tank.setProxy(null);
if (inventorySubs != null) {
inventorySubs.unsubscribe();
inventorySubs = null;
if (outputInventorySubs != null) {
outputInventorySubs.unsubscribe();
outputInventorySubs = null;
}
if (tankSubs != null) {
tankSubs.unsubscribe();
tankSubs = null;
if (outputTankSubs != null) {
outputTankSubs.unsubscribe();
outputTankSubs = null;
}
}

@Override
public void addedToController(IMultiController controller) {
super.addedToController(controller);
if (controller instanceof CokeOvenMachine cokeOven) {
inventorySubs = cokeOven.exportItems.addChangedListener(this::updateAutoIOSubscription);
tankSubs = cokeOven.exportFluids.addChangedListener(this::updateAutoIOSubscription);
inventory.setProxy(new ItemTransferList(cokeOven.importItems, cokeOven.exportItems));
outputInventorySubs = cokeOven.exportItems.addChangedListener(this::updateAutoIOSubscription);
outputTankSubs = cokeOven.exportFluids.addChangedListener(this::updateAutoIOSubscription);
inputInventory.setProxy(cokeOven.importItems);
outputInventory.setProxy(cokeOven.exportItems);
tank.setProxy(cokeOven.exportFluids);
}
}

@Override
public void removedFromController(IMultiController controller) {
super.removedFromController(controller);
inventory.setProxy(null);
inputInventory.setProxy(null);
outputInventory.setProxy(null);
tank.setProxy(null);
if (inventorySubs != null) {
inventorySubs.unsubscribe();
inventorySubs = null;
if (outputInventorySubs != null) {
outputInventorySubs.unsubscribe();
outputInventorySubs = null;
}
if (tankSubs != null) {
tankSubs.unsubscribe();
tankSubs = null;
if (outputTankSubs != null) {
outputTankSubs.unsubscribe();
outputTankSubs = null;
}
}

Expand All @@ -102,6 +105,11 @@ public boolean canShared() {
return false;
}

@Override
public boolean replacePartModelWhenFormed() {
return false;
}

//////////////////////////////////////
//******** Auto IO *********//
//////////////////////////////////////
Expand All @@ -119,7 +127,7 @@ public void onRotated(Direction oldFacing, Direction newFacing) {
}

protected void updateAutoIOSubscription() {
if ((!inventory.isEmpty() && ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null) ||
if ((!outputInventory.isEmpty() && ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null) ||
(!tank.isEmpty() && FluidTransferHelper.getFluidTransfer(getLevel(), getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null)) {
autoIOSubs = subscribeServerTick(autoIOSubs, this::autoIO);
} else if (autoIOSubs != null) {
Expand All @@ -130,7 +138,7 @@ protected void updateAutoIOSubscription() {

protected void autoIO() {
if (getOffsetTimer() % 5 == 0) {
inventory.exportToNearby(getFrontFacing());
outputInventory.exportToNearby(getFrontFacing());
tank.exportToNearby(getFrontFacing());
updateAutoIOSubscription();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@
"item.gtceu.board.phenolic.tooltip": "pɹɐoᗺ poo⅁ Ɐㄥ§",
"item.gtceu.board.plastic.tooltip": "pɹɐoᗺ poo⅁ Ɐㄥ§",
"item.gtceu.board.wetware.tooltip": "ǝɟıן sdǝǝʞ ʇɐɥʇ pɹɐoᗺ ǝɥ⟘ㄥ§",
"item.gtceu.bolt_extruder_mold": ")pןoᗺ( pןoW ɹǝpnɹʇxƎ",
"item.gtceu.bolt_extruder_mold": ")ʇןoᗺ( pןoW ɹǝpnɹʇxƎ",
"item.gtceu.bottle.purple.drink.tooltip": "¡ʞuıɹᗡ ǝןdɹnԀ ʇob I ¿ɐǝ⟘ ǝɔI ǝɯos ɹO ˙ǝpɐuoɯǝꞀ ʇnoqɐ ʍoHㄥ§",
"item.gtceu.bottle_casting_mold": ")ǝןʇʇoᗺ( pןoW buıʇsɐƆ",
"item.gtceu.bottle_extruder_mold": ")ǝןʇʇoᗺ( pןoW ɹǝpnɹʇxƎ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@
"item.gtceu.board.phenolic.tooltip": "§7A Good Board",
"item.gtceu.board.plastic.tooltip": "§7A Good Board",
"item.gtceu.board.wetware.tooltip": "§7The Board that keeps life",
"item.gtceu.bolt_extruder_mold": "Extruder Mold (Bold)",
"item.gtceu.bolt_extruder_mold": "Extruder Mold (Bolt)",
"item.gtceu.bottle.purple.drink.tooltip": "§7How about Lemonade. Or some Ice Tea? I got Purple Drink!",
"item.gtceu.bottle_casting_mold": "Casting Mold (Bottle)",
"item.gtceu.bottle_extruder_mold": "Extruder Mold (Bottle)",
Expand Down
2 changes: 1 addition & 1 deletion forge/src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@
"item.gtceu.board.phenolic.tooltip": "pɹɐoᗺ poo⅁ Ɐㄥ§",
"item.gtceu.board.plastic.tooltip": "pɹɐoᗺ poo⅁ Ɐㄥ§",
"item.gtceu.board.wetware.tooltip": "ǝɟıן sdǝǝʞ ʇɐɥʇ pɹɐoᗺ ǝɥ⟘ㄥ§",
"item.gtceu.bolt_extruder_mold": ")pןoᗺ( pןoW ɹǝpnɹʇxƎ",
"item.gtceu.bolt_extruder_mold": ")ʇןoᗺ( pןoW ɹǝpnɹʇxƎ",
"item.gtceu.bottle.purple.drink.tooltip": "¡ʞuıɹᗡ ǝןdɹnԀ ʇob I ¿ɐǝ⟘ ǝɔI ǝɯos ɹO ˙ǝpɐuoɯǝꞀ ʇnoqɐ ʍoHㄥ§",
"item.gtceu.bottle_casting_mold": ")ǝןʇʇoᗺ( pןoW buıʇsɐƆ",
"item.gtceu.bottle_extruder_mold": ")ǝןʇʇoᗺ( pןoW ɹǝpnɹʇxƎ",
Expand Down
2 changes: 1 addition & 1 deletion forge/src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@
"item.gtceu.board.phenolic.tooltip": "§7A Good Board",
"item.gtceu.board.plastic.tooltip": "§7A Good Board",
"item.gtceu.board.wetware.tooltip": "§7The Board that keeps life",
"item.gtceu.bolt_extruder_mold": "Extruder Mold (Bold)",
"item.gtceu.bolt_extruder_mold": "Extruder Mold (Bolt)",
"item.gtceu.bottle.purple.drink.tooltip": "§7How about Lemonade. Or some Ice Tea? I got Purple Drink!",
"item.gtceu.bottle_casting_mold": "Casting Mold (Bottle)",
"item.gtceu.bottle_extruder_mold": "Extruder Mold (Bottle)",
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencyResolutionManagement {
def architecturyLoomVersion = "1.0-SNAPSHOT"
def vineFlowerVersion = "1.+"
def macheteVersion = "1.+"
def ldLibVersion = "1.0.16"
def ldLibVersion = "1.0.16.a"

fabric {
def parchment = version("parchment", parchmentVersion)
Expand Down

0 comments on commit f646830

Please sign in to comment.