Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Bug fixes and some new features #84

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
import com.lowdragmc.multiblocked.api.pattern.Predicates;
import com.lowdragmc.multiblocked.api.pattern.util.RelativeDirection;
import com.lowdragmc.multiblocked.api.recipe.ItemsIngredient;
import com.lowdragmc.multiblocked.api.recipe.RecipeLogic;
import com.lowdragmc.multiblocked.api.recipe.RecipeMap;
import dev.latvian.kubejs.KubeJSPlugin;
import dev.latvian.kubejs.fluid.FluidStackJS;
import dev.latvian.kubejs.item.ItemStackJS;
import dev.latvian.kubejs.item.ingredient.IngredientJS;
import dev.latvian.kubejs.script.BindingsEvent;
import dev.latvian.kubejs.script.ScriptType;
import dev.latvian.kubejs.util.MapJS;
import dev.latvian.mods.rhino.mod.util.NBTWrapper;
import dev.latvian.mods.rhino.util.wrap.TypeWrappers;
import me.shedaniel.architectury.hooks.forge.FluidStackHooksForge;
import net.minecraft.nbt.INBT;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraftforge.fluids.FluidStack;

Expand All @@ -47,6 +51,7 @@ public void addBindings(BindingsEvent event) {
event.add("MbdIO", IO.class);
event.add("Shapes", VoxelShapes.class);
event.add("ICapabilityProxyHolder", ICapabilityProxyHolder.class);
event.add("MbdRecipeStatus", RecipeLogic.Status.class);

// LDLib Widget
event.add("ModularUI", ModularUI.class);
Expand Down Expand Up @@ -86,6 +91,9 @@ public void addBindings(BindingsEvent event) {
event.add("RecipeWidget", RecipeWidget.class);
event.add("GuiSize", Size.class);
event.add("GuiPos", Position.class);

//kubejs utils
event.add("NBTUtils", NBTUtils.class);
}

@Override
Expand All @@ -94,6 +102,7 @@ public void addTypeWrappers(ScriptType type, TypeWrappers typeWrappers) {
if (typeWrappers.getWrapperFactory(FluidStack.class, null) == null) {
typeWrappers.register(FluidStack.class, MultiblockedJSPlugin::FluidStackWrapper);
}
typeWrappers.register(INBT.class, MultiblockedJSPlugin::INBTWrapper);
}

public static FluidStack FluidStackWrapper(Object o) {
Expand All @@ -108,4 +117,8 @@ public static ItemsIngredient ItemsIngredientWrapper(Object o) {
IngredientJS ingredient = IngredientJS.of(o);
return new ItemsIngredient(ingredient.createVanillaIngredient());
}
public static INBT INBTWrapper(Object o) {
INBT result = (MapJS.isNbt(o)) ? MapJS.nbt(o) : NBTWrapper.toTag(o);
return (result == null) ? NBTWrapper.compoundTag() : result;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/lowdragmc/multiblocked/api/kubejs/NBTUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.lowdragmc.multiblocked.api.kubejs;

import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;


public class NBTUtils {
//put value into tag0
public static INBT putTagInto(CompoundNBT tag0, String key, INBT value) {
return tag0.put(key, value);
}

//merge tag1 with tag0
public static INBT mergeTags(CompoundNBT tag0, CompoundNBT tag1) {
return tag0.merge(tag1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void update() {
if (getStatus() == Status.WORKING) {
handleRecipeWorking();
}
if (progress == duration) {
if (progress >= duration) {
onRecipeFinish();
}
}
Expand Down Expand Up @@ -202,6 +202,10 @@ public void setStatus(Status status) {
}
}

public void setStatus(String statusName) {
this.setStatus(Status.valueOf(statusName));
}

public Status getStatus() {
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer;
import com.lowdragmc.multiblocked.persistence.MultiblockWorldSavedData;
import dev.latvian.kubejs.script.ScriptType;
import dev.latvian.mods.rhino.mod.util.NBTWrapper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -156,6 +157,13 @@ public void setOwner(PlayerEntity player) {
this.owner = player.getUUID();
}

public INBT getPersistedData() {
return this.persistedData;
}
public void setPersistedData(INBT data) {
this.persistedData = data;
}

public void update(){
timer++;
if (Multiblocked.isKubeJSLoaded() && level != null) {
Expand Down