-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/origin/1902' into 2001
# Conflicts: # common/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
common/src/main/java/dev/latvian/mods/kubejs/block/custom/CarpetBlockBuilder.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,40 @@ | ||
package dev.latvian.mods.kubejs.block.custom; | ||
|
||
import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator; | ||
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.BlockTags; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.CarpetBlock; | ||
|
||
public class CarpetBlockBuilder extends ShapedBlockBuilder { | ||
public CarpetBlockBuilder(ResourceLocation i) { | ||
super(i, "_carpet"); | ||
tagBoth(BlockTags.WOOL_CARPETS.location()); | ||
} | ||
|
||
@Override | ||
public Block createObject() { | ||
return new CarpetBlock(createProperties()); | ||
} | ||
|
||
@Override | ||
protected void generateBlockStateJson(VariantBlockStateGenerator bs) { | ||
var mod = newID("block/", "").toString(); | ||
bs.variant("", (v) -> v.model(mod)); | ||
} | ||
|
||
@Override | ||
protected void generateBlockModelJsons(AssetJsonGenerator generator) { | ||
var texture = textures.get("texture").getAsString(); | ||
|
||
generator.blockModel(id, m -> { | ||
m.parent("minecraft:block/carpet"); | ||
m.texture("wool", texture); | ||
}); | ||
} | ||
|
||
public CarpetBlockBuilder texture(String texture) { | ||
return (CarpetBlockBuilder) textureAll(texture); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
fabric/src/main/java/dev/latvian/mods/kubejs/core/mixin/fabric/ShapedRecipeMixin.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,54 @@ | ||
package dev.latvian.mods.kubejs.core.mixin.fabric; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import dev.latvian.mods.rhino.mod.util.NBTUtils; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.TagParser; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(net.minecraft.world.item.crafting.ShapedRecipe.class) | ||
public class ShapedRecipeMixin { | ||
@Inject( | ||
method = "itemStackFromJson", | ||
at = @At( | ||
value = "RETURN", | ||
remap = false | ||
), | ||
cancellable = false | ||
) | ||
private static void itemStackFromJson(JsonObject jsonObject, CallbackInfoReturnable<ItemStack> cir) { | ||
if(cir.getReturnValue() == null || cir.getReturnValue() == ItemStack.EMPTY) { | ||
return; | ||
} | ||
|
||
if(jsonObject.has("nbt")) { | ||
var json = jsonObject.get("nbt"); | ||
// Process null | ||
if (json == null || json.isJsonNull()) { | ||
return; | ||
} | ||
|
||
try { | ||
CompoundTag tag = null; | ||
if (json.isJsonObject()) { | ||
// We use a normal .toString() to convert the json to string, and read it as SNBT. | ||
// Using DynamicOps would mess with the type of integers and cause things like damage comparisons to fail... | ||
tag = TagParser.parseTag(json.toString()); | ||
} else { | ||
// Assume it's a string representation of the NBT | ||
tag = TagParser.parseTag(GsonHelper.convertToString(json, "nbt")); | ||
} | ||
cir.getReturnValue().getOrCreateTag().merge(tag); | ||
} catch (CommandSyntaxException commandSyntaxException) { | ||
throw new JsonSyntaxException("Invalid nbt tag: " + commandSyntaxException.getMessage()); | ||
} | ||
} | ||
} | ||
} |
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