Archive eaglerforge-builder (tool, 1.8.8, clean)
This commit is contained in:
@@ -0,0 +1,225 @@
|
||||
//TODO: quantityDropped, onBlockDestroyedByExplosion, onBlockActivated
|
||||
PRIMITIVES["block_advanced"] = {
|
||||
name: "Advanced Block",
|
||||
uses: ["fixup_block_ids", "str2ab"],
|
||||
type: "block_advanced",
|
||||
tags: {
|
||||
id: "advanced_block",
|
||||
name: "Advanced Block",
|
||||
texture: VALUE_ENUMS.IMG,
|
||||
animatedSpritesheetTexture: false, // https://sheeptester.github.io/words-go-here/misc/animated-painting-maker.html
|
||||
animatedTextureFrameDuration: 1,
|
||||
animatedTextureInterpolate: false,
|
||||
tickRatio: 10,
|
||||
material: ['rock', 'air', 'grass', 'ground', 'wood', 'iron', 'anvil', 'water', 'lava', 'leaves', 'plants', 'vine', 'sponge', 'cloth', 'fire', 'sand', 'circuits', 'carpet', 'glass', 'redstoneLight', 'tnt', 'coral', 'ice', 'packedIce', 'snow', 'craftedSnow', 'cactus', 'clay', 'gourd', 'dragonEgg', 'portal', 'cake', 'web', 'piston', 'barrier'],
|
||||
Constructor: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockConstructor",
|
||||
Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak",
|
||||
Added: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockAdded",
|
||||
NeighborChange: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockNeighbourChange",
|
||||
Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak",
|
||||
BrokenByPlayer: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBrokenByPlayer",
|
||||
RandomTick: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockRandomTick",
|
||||
EntityCollided: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockEntityCollision",
|
||||
GetDroppedItem: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockGetDroppedItem",
|
||||
QuantityDropped: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockQuantityDropped",
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
var constructorHandler = getHandlerCode("BlockConstructor", this.tags.Constructor, []);
|
||||
var breakHandler = getHandlerCode("BlockBreak", this.tags.Break, ["$$world", "$$blockpos", "$$blockstate"]);
|
||||
var addedHandler = getHandlerCode("BlockAdded", this.tags.Added, ["$$world", "$$blockpos", "$$blockstate"]);
|
||||
var neighborHandler = getHandlerCode("BlockNeighbourChange", this.tags.NeighborChange, ["$$world", "$$blockpos", "$$blockstate"], {
|
||||
"1_8": function (args, code) {
|
||||
return `
|
||||
var $$onNeighborBlockChangeMethod = $$blockClass.methods.onNeighborBlockChange.method;
|
||||
$$nmb_AdvancedBlock.prototype.$onNeighborBlockChange = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return $$onNeighborBlockChangeMethod(this, ${args.join(", ")});
|
||||
}
|
||||
`
|
||||
},
|
||||
"1_12": function (args, code) {
|
||||
const copy = [...args];
|
||||
copy[0] = args[1];
|
||||
copy[1] = args[2];
|
||||
copy[2] = args[0];
|
||||
return `
|
||||
var $$onNeighborBlockChangeMethod = $$blockClass.methods.neighborChanged.method;
|
||||
$$nmb_AdvancedBlock.prototype.$neighborChanged = function (${copy.join(", ")}) {
|
||||
${code};
|
||||
return $$onNeighborBlockChangeMethod(this, ${copy.join(", ")});
|
||||
}
|
||||
`
|
||||
}
|
||||
});
|
||||
var brokenByPlayerHandler = getHandlerCode("BlockBrokenByPlayer", this.tags.BrokenByPlayer, ["$$world", "$$blockpos", "$$blockstate"]);
|
||||
var randomTickHandler = getHandlerCode("BlockRandomTick", this.tags.RandomTick, ["$$world", "$$blockpos", "$$blockstate", "$$random"]);
|
||||
var entityCollisionHandler = getHandlerCode("BlockEntityCollision", this.tags.EntityCollided, ["$$world", "$$blockpos", "$$entity"], {
|
||||
"1_8": function (args, code) {
|
||||
return `
|
||||
var $$entityCollisionMethod = $$blockClass.methods.onEntityCollidedWithBlock.method;
|
||||
$$nmb_AdvancedBlock.prototype.$onEntityCollidedWithBlock = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return $$entityCollisionMethod(this, ${args.join(", ")});
|
||||
}`;
|
||||
},
|
||||
"1_12": function (args, code) {
|
||||
const argList = `${args.slice(0,2).join(", ")},$$blockstate,${args[2]}`;
|
||||
return `
|
||||
var $$entityCollisionMethod = $$blockClass.methods.onEntityCollidedWithBlock.method;
|
||||
$$nmb_AdvancedBlock.prototype.$onEntityCollidedWithBlock = function (${argList}) {
|
||||
${code};
|
||||
return $$entityCollisionMethod(this, ${argList});
|
||||
}`;
|
||||
}
|
||||
});
|
||||
var getDroppedItemHandler = getHandlerCode("BlockGetDroppedItem", this.tags.GetDroppedItem, ["$$blockstate", "$$random", "$$forture"]);
|
||||
var quantityDroppedHandler = getHandlerCode("BlockQuantityDropped", this.tags.QuantityDropped, ["$$random", "$$fortune"]);
|
||||
|
||||
var animationCode = `
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/${this.tags.id}.png.mcmeta", efb2__str2ab(
|
||||
\`{
|
||||
"animation": {
|
||||
"frametime": ${Math.max(1, Math.round(this.tags.animatedTextureFrameDuration)) || 1},
|
||||
"interpolate": ${this.tags.animatedTextureInterpolate}
|
||||
}
|
||||
}\`));
|
||||
`;
|
||||
|
||||
return `(function AdvancedBlockDatablock() {
|
||||
const $$blockTexture = "${this.tags.texture}";
|
||||
|
||||
function $$ServersideBlocks() {
|
||||
const $$scoped_efb_globals = {};
|
||||
var $$itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||
var $$blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||
var $$iproperty = ModAPI.reflect.getClassById("net.minecraft.block.properties.IProperty").class;
|
||||
var $$makeBlockState = ModAPI.reflect.getClassById("${flags.target === "1_12" ? "net.minecraft.block.state.BlockStateContainer" : "net.minecraft.block.state.BlockState"}").constructors.find(x => x.length === 2);
|
||||
var $$blockSuper = ModAPI.reflect.getSuper($$blockClass, (x) => x.length === 2);
|
||||
|
||||
var $$breakBlockMethod = $$blockClass.methods.breakBlock.method;
|
||||
var $$onBlockAddedMethod = $$blockClass.methods.onBlockAdded.method;
|
||||
var $$onBlockDestroyedByPlayerMethod = $$blockClass.methods.onBlockDestroyedByPlayer.method;
|
||||
var $$randomTickMethod = $$blockClass.methods.randomTick.method;
|
||||
|
||||
var $$getDroppedItem = $$blockClass.methods.getItemDropped.method;
|
||||
var $$quantityDropped = $$blockClass.methods.quantityDropped.method;
|
||||
|
||||
var $$nmb_AdvancedBlock = function $$nmb_AdvancedBlock() {
|
||||
$$blockSuper(this, ModAPI.materials.${this.tags.material}.getRef());
|
||||
${flags.target === "1_12" ? "//" : ""}this.$defaultBlockState = this.$blockState.$getBaseState();
|
||||
${constructorHandler.code};
|
||||
}
|
||||
ModAPI.reflect.prototypeStack($$blockClass, $$nmb_AdvancedBlock);
|
||||
$$nmb_AdvancedBlock.prototype.$isOpaqueCube = function () {
|
||||
return 1;
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$createBlockState = function () {
|
||||
return $$makeBlockState(this, ModAPI.array.object($$iproperty, 0));
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$breakBlock = function (${breakHandler.args.join(", ")}) {
|
||||
${breakHandler.code};
|
||||
return $$breakBlockMethod(this, ${breakHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$onBlockAdded = function (${addedHandler.args.join(", ")}) {
|
||||
${addedHandler.code};
|
||||
return $$onBlockAddedMethod(this, ${addedHandler.args.join(", ")});
|
||||
}
|
||||
|
||||
${neighborHandler}
|
||||
|
||||
$$nmb_AdvancedBlock.prototype.$onBlockDestroyedByPlayer = function (${brokenByPlayerHandler.args.join(", ")}) {
|
||||
${brokenByPlayerHandler.code};
|
||||
return $$onBlockDestroyedByPlayerMethod(this, ${brokenByPlayerHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$randomTick = function (${randomTickHandler.args.join(", ")}) {
|
||||
${randomTickHandler.code};
|
||||
return $$randomTickMethod(this, ${randomTickHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$tickRate = function () {
|
||||
return ${Math.max(1, Math.floor(this.tags.tickRatio || 10))};
|
||||
}
|
||||
|
||||
${entityCollisionHandler}
|
||||
|
||||
$$nmb_AdvancedBlock.prototype.$getItemDropped = function (${getDroppedItemHandler.args.join(", ")}) {
|
||||
${getDroppedItemHandler.code};
|
||||
return $$getDroppedItem(this, ${getDroppedItemHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$quantityDropped = function (${quantityDroppedHandler.args.join(", ")}) {
|
||||
${quantityDroppedHandler.code};
|
||||
return $$quantityDropped(this, ${quantityDroppedHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$quantityDroppedWithBonus = function (${quantityDroppedHandler.args.reverse().join(", ")}) {
|
||||
${quantityDroppedHandler.code};
|
||||
return $$quantityDropped(this, ${quantityDroppedHandler.args.reverse().join(", ")});
|
||||
}
|
||||
|
||||
function $$internal_reg() {
|
||||
var $$cblock = (new $$nmb_AdvancedBlock()).$setUnlocalizedName(
|
||||
ModAPI.util.str("${this.tags.id}")
|
||||
);
|
||||
$$blockClass.staticMethods.registerBlock0.method(
|
||||
ModAPI.keygen.block("${this.tags.id}"),
|
||||
ModAPI.util.str("${this.tags.id}"),
|
||||
$$cblock
|
||||
);
|
||||
$$itemClass.staticMethods.registerItemBlock0.method($$cblock);
|
||||
efb2__fixupBlockIds();
|
||||
ModAPI.blocks["${this.tags.id}"] = $$cblock;
|
||||
|
||||
return $$cblock;
|
||||
}
|
||||
|
||||
if (ModAPI.materials) {
|
||||
return $$internal_reg();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", $$internal_reg);
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode($$ServersideBlocks);
|
||||
var $$cblock = $$ServersideBlocks();
|
||||
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||
ModAPI.addEventListener("lib:asyncsink:registeritems", ($$renderItem)=>{
|
||||
$$renderItem.registerBlock($$cblock, ModAPI.util.str("${this.tags.id}"));
|
||||
});
|
||||
AsyncSink.L10N.set("tile.${this.tags.id}.name", "${this.tags.name}");
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/block/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "blocks/${this.tags.id}"
|
||||
}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"parent": "block/${this.tags.id}",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [10, -45, 170],
|
||||
"translation": [0, 1.5, -2.75],
|
||||
"scale": [0.375, 0.375, 0.375]
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/blockstates/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"variants": {
|
||||
"normal": [
|
||||
{ "model": "${this.tags.id}" },
|
||||
]
|
||||
}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/${this.tags.id}.png", await (await fetch(
|
||||
$$blockTexture
|
||||
)).arrayBuffer());
|
||||
${this.tags.animatedSpritesheetTexture ? animationCode : ""}
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
PRIMITIVES["command"] = {
|
||||
name: "Command",
|
||||
uses: [],
|
||||
type: "command",
|
||||
tags: {
|
||||
command: "/example_command",
|
||||
caseSensitive: false,
|
||||
playersOnly: true,
|
||||
CalledByPlayer: VALUE_ENUMS.ABSTRACT_HANDLER + "CommandCalledByPlayer",
|
||||
CalledByOther: VALUE_ENUMS.ABSTRACT_HANDLER + "CommandCalled",
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
var escaped = this.tags.command.replaceAll("\"", "\\\"");
|
||||
var len = this.tags.command.length;
|
||||
var callHandler = getHandlerCode("CommandCalled", this.tags.CalledByOther, ["$$args", "$$sender"]);
|
||||
var callPlayerHandler = getHandlerCode("CommandCalledByPlayer", this.tags.CalledByPlayer, ["$$args", "$$sender", "$$player"]);
|
||||
return `
|
||||
(function CommandDatablock() {
|
||||
PluginAPI.dedicatedServer.appendCode(function () {
|
||||
const $$scoped_efb_globals = {};
|
||||
PluginAPI.addEventListener("processcommand", ($$event) => {
|
||||
if ($$event.command${this.tags.caseSensitive ? "" : ".toLowerCase()"}.startsWith("${escaped}")) {
|
||||
var $$arguments = $$event.command.substring(${len + 1}).trim().split(" ").filter(x=>!!x);
|
||||
var $$isPlayer = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf($$event.sender.getRef());
|
||||
if (
|
||||
$$isPlayer
|
||||
) {
|
||||
(function (${callPlayerHandler.args.join(",")}) {${callPlayerHandler.code}})($$arguments, $$event.sender.getRef(), $$event.sender.getRef());
|
||||
}${this.tags.playersOnly ? "" : ` else {
|
||||
(function (${callHandler.args.join(",")}) {${callHandler.code}})($$arguments, $$event.sender.getRef());
|
||||
}`}
|
||||
$$event.preventDefault = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
//TODO: quantityDropped, onBlockDestroyedByExplosion, onBlockActivated
|
||||
PRIMITIVES["recipe"] = {
|
||||
name: "Crafting Recipe",
|
||||
uses: [],
|
||||
type: "recipe",
|
||||
tags: {
|
||||
slot0: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot1: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot2: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf0: VALUE_ENUMS.NEWLINE,
|
||||
slot3: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot4: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot5: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf1: VALUE_ENUMS.NEWLINE,
|
||||
slot6: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot7: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot8: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf2: VALUE_ENUMS.NEWLINE,
|
||||
lf3: VALUE_ENUMS.NEWLINE,
|
||||
resultQuantity: 1,
|
||||
result: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf4: VALUE_ENUMS.NEWLINE,
|
||||
ModifyResult: VALUE_ENUMS.ABSTRACT_HANDLER + "CraftingRecipeModifyResult",
|
||||
},
|
||||
getDependencies: function () {
|
||||
const matchesList = new Set([].bake().dynamicConcat("block_advanced", "id", (x) => {
|
||||
return "block/" + x + "@0"
|
||||
}).dynamicConcat("item", "id", (x) => {
|
||||
return "item/" + x
|
||||
}).calculate());
|
||||
const possibleDepsList = new Set([
|
||||
this.tags.slot0,
|
||||
this.tags.slot1,
|
||||
this.tags.slot2,
|
||||
this.tags.slot3,
|
||||
this.tags.slot4,
|
||||
this.tags.slot5,
|
||||
this.tags.slot6,
|
||||
this.tags.slot7,
|
||||
this.tags.slot8,
|
||||
this.tags.result
|
||||
]);
|
||||
const deps = [...matchesList.intersection(possibleDepsList)].map(x => {
|
||||
if (x.startsWith("block/")) {
|
||||
x = x.replace("block/", "").split("@");
|
||||
x = x[0];
|
||||
return state.nodes.find(y => (y.type === "block_advanced") && (y.tags.id === x))
|
||||
} else {
|
||||
x = x.replace("item/", "");
|
||||
return state.nodes.find(y => (y.type === "item") && (y.tags.id === x))
|
||||
}
|
||||
});
|
||||
return deps;
|
||||
},
|
||||
asJavaScript: function () {
|
||||
Object.keys(this.tags).forEach(k => {
|
||||
this.tags[k] = (this.tags[k] === VALUE_ENUMS.ABSTRACT_ITEM) ? "item/air" : this.tags[k];
|
||||
});
|
||||
const grid = [
|
||||
[this.tags.slot0, this.tags.slot1, this.tags.slot2],
|
||||
[this.tags.slot3, this.tags.slot4, this.tags.slot5],
|
||||
[this.tags.slot6, this.tags.slot7, this.tags.slot8]
|
||||
];
|
||||
var minX = 2;
|
||||
var minY = 2;
|
||||
var maxX = 0;
|
||||
var maxY = 0;
|
||||
for (let y = 0; y < grid.length; y++) {
|
||||
const row = grid[y];
|
||||
for (let x = 0; x < row.length; x++) {
|
||||
const cell = row[x];
|
||||
if (cell === "item/air") {
|
||||
continue;
|
||||
}
|
||||
minX = Math.min(minX, x);
|
||||
minY = Math.min(minY, y);
|
||||
maxX = Math.max(maxX, x);
|
||||
maxY = Math.max(maxY, y);
|
||||
}
|
||||
}
|
||||
minX = Math.min(minX, maxX);
|
||||
minY = Math.min(minY, maxY);
|
||||
maxX = Math.max(maxX, minX);
|
||||
maxY = Math.max(maxY, minY);
|
||||
const newGrid = (new Array((maxY + 1) - minY)).fill([]).map(() => (new Array((maxX + 1) - minX)).fill("item/air"));
|
||||
for (let x = minX; x < (maxX + 1); x++) {
|
||||
for (let y = minY; y < (maxY + 1); y++) {
|
||||
newGrid[y - minY][x - minX] = grid[y][x];
|
||||
}
|
||||
}
|
||||
const uniqueTypesMap = Object.fromEntries([...new Set(newGrid.flat())].filter(x => x !== "item/air").map((x, i) => {
|
||||
return [x, String.fromCharCode(65 + i)];
|
||||
}));
|
||||
const uniqueTypesMapReverse = Object.fromEntries([...new Set(newGrid.flat())].filter(x => x !== "item/air").map((x, i) => {
|
||||
return [String.fromCharCode(65 + i), x];
|
||||
}));
|
||||
var legendStr = "";
|
||||
const ks = Object.keys(uniqueTypesMapReverse);
|
||||
ks.forEach((k, i) => {
|
||||
if (flags.target === "1_12") {
|
||||
legendStr += `"${k}": {
|
||||
item: "minecraft:${uniqueTypesMapReverse[k].split("/")[1].split("@")[0]}",
|
||||
${uniqueTypesMapReverse[k].includes("@") ? `data: ${parseInt(uniqueTypesMapReverse[k].split("/")[1].split("@")[1]) || 0}` : ""}
|
||||
}${ks.length === (i+1) ? "" : ","}`
|
||||
} else {
|
||||
legendStr += `"${k}": {
|
||||
type: "${uniqueTypesMapReverse[k].split("/")[0]}",
|
||||
id: "${uniqueTypesMapReverse[k].split("/")[1].split("@")[0]}",
|
||||
${uniqueTypesMapReverse[k].includes("@") ? `meta: ${parseInt(uniqueTypesMapReverse[k].split("/")[1].split("@")[1]) || 0}` : ""}
|
||||
}${ks.length === (i+1) ? "" : ","}`
|
||||
}
|
||||
});
|
||||
var $$recipePattern = "";
|
||||
for (let y = 0; y < newGrid.length; y++) {
|
||||
const row = newGrid[y];
|
||||
$$recipePattern += '"';
|
||||
for (let x = 0; x < row.length; x++) {
|
||||
const cell = row[x];
|
||||
$$recipePattern += `${cell === "item/air" ? " " : uniqueTypesMap[cell]}`
|
||||
}
|
||||
$$recipePattern += '"';
|
||||
$$recipePattern += ",";
|
||||
}
|
||||
var modifyResultHandler = getHandlerCode("CraftingRecipeModifyResult", this.tags.ModifyResult, ["$$itemstack"]);
|
||||
if (flags.target === "1_12") {
|
||||
return `(function CraftingRecipeDatablock112() {
|
||||
|
||||
async function registerRecipe(isServer) {
|
||||
if (isServer) {
|
||||
await new Promise((res, rej) => {
|
||||
ModAPI.addEventListener("bootstrap", res);
|
||||
});
|
||||
}
|
||||
const parseJson = ModAPI.reflect.getClassByName("JSONObject").constructors.findLast(x => x.length === 1);
|
||||
const CraftingManager = ModAPI.reflect.getClassByName("CraftingManager");
|
||||
const CraftingManagerMethods = CraftingManager.staticMethods;
|
||||
const jsonData = parseJson(ModAPI.util.str(\`{
|
||||
"type": "crafting_shaped", ${/*/or crafting_shapeless/*/""}
|
||||
"pattern": [
|
||||
${$$recipePattern}
|
||||
],
|
||||
"key": {
|
||||
${legendStr}
|
||||
},
|
||||
"result": {
|
||||
"item": "minecraft:${this.tags.result.split("/")[1].split("@")[0]}",
|
||||
"data": ${this.tags.result.split("/")[1].split("@")[1] || "0"},
|
||||
"count": ${this.tags.resultQuantity}
|
||||
}
|
||||
}\`.trim()));
|
||||
const recipeObj = CraftingManagerMethods.func_193376_a.method(jsonData); //convert json to an IRecipe
|
||||
CraftingManagerMethods.func_193379_a.method(ModAPI.util.str("coolrecipeid"), recipeObj); //register recipe under resource location
|
||||
}
|
||||
|
||||
ModAPI.dedicatedServer.appendCode(registerRecipe);
|
||||
registerRecipe(false);
|
||||
})();
|
||||
`;
|
||||
} else {
|
||||
return `(function CraftingRecipeDatablock() {
|
||||
function $$registerRecipe() {
|
||||
function $$internalRegister() {
|
||||
const $$scoped_efb_globals = {};
|
||||
var $$ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class;
|
||||
function $$ToChar(char) {
|
||||
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
||||
}
|
||||
var $$resultItemArg = "${this.tags.result.replace("item/air", "block/air")}";
|
||||
var $$recipeLegend = {
|
||||
${legendStr}
|
||||
};
|
||||
var $$recipePattern = [
|
||||
${$$recipePattern}
|
||||
];
|
||||
var $$itemStackFromBlockWithMeta = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[2];
|
||||
var $$itemStackFromItem = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[4];
|
||||
var $$recipeInternal = [];
|
||||
Object.keys($$recipeLegend).forEach(($$key) => {
|
||||
$$recipeInternal.push($$ToChar($$key));
|
||||
var $$ingredient = ($$recipeLegend[$$key].type === "block" ? $$itemStackFromBlockWithMeta(ModAPI.blocks[$$recipeLegend[$$key].id].getRef(),1,$$recipeLegend[$$key].meta) : ModAPI.items[$$recipeLegend[$$key].id].getRef());
|
||||
$$recipeInternal.push($$ingredient);
|
||||
});
|
||||
|
||||
var $$recipeContents = $$recipePattern.map(row => ModAPI.util.str(row));
|
||||
var $$recipe = ModAPI.util.makeArray($$ObjectClass, $$recipeContents.concat($$recipeInternal));
|
||||
|
||||
var $$resultItem = $$resultItemArg.startsWith("block/") ?
|
||||
($$itemStackFromBlockWithMeta(ModAPI.blocks[$$resultItemArg.replace("block/", "").split("@")[0]].getRef(),${this.tags.resultQuantity},$$resultItemArg.replace("block/", "").split("@")[1] || 0))
|
||||
: ($$itemStackFromItem(ModAPI.items[$$resultItemArg.replace("item/", "")].getRef(), ${this.tags.resultQuantity}));
|
||||
|
||||
(function (${modifyResultHandler.args.join(",")}) {${modifyResultHandler.code}})($$resultItem);
|
||||
|
||||
var $$craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
||||
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe($$craftingManager, $$resultItem, $$recipe);
|
||||
|
||||
}
|
||||
|
||||
if (ModAPI.items) {
|
||||
$$internalRegister();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", $$internalRegister);
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode($$registerRecipe);
|
||||
$$registerRecipe();
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
PRIMITIVES["furnace_recipe"] = {
|
||||
name: "Furnace Recipe",
|
||||
uses: [],
|
||||
type: "furnace_recipe",
|
||||
tags: {
|
||||
input: VALUE_ENUMS.ABSTRACT_ITEM, // item/block to smelt
|
||||
lf0: VALUE_ENUMS.NEWLINE,
|
||||
lf1: VALUE_ENUMS.NEWLINE,
|
||||
resultQuantity: 1, // output count
|
||||
result: VALUE_ENUMS.ABSTRACT_ITEM, // smelt result
|
||||
lf3: VALUE_ENUMS.NEWLINE,
|
||||
experience: 0.1, // xp gained
|
||||
},
|
||||
getDependencies: function () {
|
||||
const deps = [];
|
||||
[this.tags.input, this.tags.result].forEach(entry => {
|
||||
if (!entry || entry === "item/air") return;
|
||||
if (entry.startsWith("block/")) {
|
||||
let id = entry.replace("block/", "").split("@")[0];
|
||||
const dep = state.nodes.find(y => y.type === "block_advanced" && y.tags.id === id);
|
||||
if (dep) deps.push(dep);
|
||||
} else if (entry.startsWith("item/")) {
|
||||
let id = entry.replace("item/", "").split("@")[0];
|
||||
const dep = state.nodes.find(y => y.type === "item" && y.tags.id === id);
|
||||
if (dep) deps.push(dep);
|
||||
}
|
||||
});
|
||||
return deps;
|
||||
},
|
||||
asJavaScript: function () {
|
||||
// Create a copy of tags to avoid modifying the original
|
||||
const tags = { ...this.tags };
|
||||
Object.keys(tags).forEach(k => {
|
||||
tags[k] = (tags[k] === VALUE_ENUMS.ABSTRACT_ITEM) ? "item/air" : tags[k];
|
||||
});
|
||||
|
||||
return `(function FurnaceRecipeDatablock() {
|
||||
async function $$registerFurnaceRecipe(isServer) {
|
||||
await new Promise((res, rej) => {
|
||||
if (!isServer) {
|
||||
res();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", res);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
const FurnaceRecipesInstance = ModAPI.util.wrap(ModAPI.reflect.getClassByName("FurnaceRecipes").staticVariables.smeltingBase);
|
||||
|
||||
function parseEntry(entry) {
|
||||
if (!entry || entry === "item/air") return null;
|
||||
|
||||
var type, id, meta = 0;
|
||||
if (entry.includes("@")) {
|
||||
const parts = entry.split("@");
|
||||
id = parts[0];
|
||||
meta = parseInt(parts[1], 10) || 0;
|
||||
} else {
|
||||
id = entry;
|
||||
}
|
||||
|
||||
if (id.startsWith("block/")) {
|
||||
type = "block";
|
||||
id = id.replace("block/", "");
|
||||
} else if (id.startsWith("item/")) {
|
||||
type = "item";
|
||||
id = id.replace("item/", "");
|
||||
} else {
|
||||
if (ModAPI.blocks && ModAPI.blocks[id]) type = "block";
|
||||
else if (ModAPI.items && ModAPI.items[id]) type = "item";
|
||||
else {
|
||||
console.warn("Unknown item/block id: " + entry);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return { type, id, meta };
|
||||
}
|
||||
|
||||
var input = parseEntry("${tags.input}");
|
||||
var output = parseEntry("${tags.result}");
|
||||
|
||||
if (!input || !output) {
|
||||
console.warn("Invalid furnace recipe: missing input or output");
|
||||
return;
|
||||
}
|
||||
|
||||
var $$outputStack;
|
||||
if (output.type === "block") {
|
||||
if (!ModAPI.blocks[output.id]) {
|
||||
console.warn("Block not found: " + output.id);
|
||||
return;
|
||||
}
|
||||
$$outputStack = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[1](ModAPI.blocks[output.id].getRef(), ${tags.resultQuantity});
|
||||
} else {
|
||||
if (!ModAPI.items[output.id]) {
|
||||
console.warn("Item not found: " + output.id);
|
||||
return;
|
||||
}
|
||||
$$outputStack = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[4](ModAPI.items[output.id].getRef(), ${tags.resultQuantity});
|
||||
}
|
||||
|
||||
if (input.type === "block") {
|
||||
if (!ModAPI.blocks[input.id]) {
|
||||
console.warn("Input block not found: " + input.id);
|
||||
return;
|
||||
}
|
||||
FurnaceRecipesInstance.addSmeltingRecipeForBlock(ModAPI.blocks[input.id].getRef(), $$outputStack, ${tags.experience});
|
||||
} else {
|
||||
if (!ModAPI.items[input.id]) {
|
||||
console.warn("Input item not found: " + input.id);
|
||||
return;
|
||||
}
|
||||
FurnaceRecipesInstance.addSmelting(ModAPI.items[input.id].getRef(), $$outputStack, ${tags.experience});
|
||||
}
|
||||
|
||||
console.log("Registered furnace recipe: " + "${tags.input}" + " -> " + "${tags.result}");
|
||||
} catch (e) {
|
||||
console.error("Error registering furnace recipe:", e);
|
||||
}
|
||||
}
|
||||
|
||||
$$registerFurnaceRecipe();
|
||||
if (ModAPI.dedicatedServer && ModAPI.dedicatedServer.appendCode) {
|
||||
ModAPI.dedicatedServer.appendCode($$registerFurnaceRecipe);
|
||||
}
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
PRIMITIVES["icon"] = {
|
||||
name: "Icon",
|
||||
uses: [],
|
||||
type: "icon",
|
||||
tags: {
|
||||
Icon: VALUE_ENUMS.IMG,
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
if (!this.tags.Icon || this.tags.Icon === VALUE_ENUMS.IMG) {
|
||||
return "";
|
||||
}
|
||||
return `
|
||||
(function IconDatablock() {
|
||||
ModAPI.meta.icon("${this.tags.Icon}");
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
PRIMITIVES["inspector"] = {
|
||||
name: "Inspector",
|
||||
uses: [],
|
||||
type: "inspector",
|
||||
hidden: true,
|
||||
tags: {
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
|
||||
var inspectorFrame = document.createElement("iframe");
|
||||
inspectorFrame.id = "inspector";
|
||||
inspectorFrame.style.position = "fixed";
|
||||
inspectorFrame.style.border = "0";
|
||||
inspectorFrame.style.display = "none";
|
||||
inspectorFrame.style.pointerEvents = "none";
|
||||
inspectorFrame.style.backgroundColor = "white";
|
||||
inspectorFrame.allowFullscreen = true;
|
||||
inspectorFrame.tabIndex = 0;
|
||||
inspectorFrame.srcdoc = "<h3>Use the 'Run' button and select an EaglerForge build.</h3>";
|
||||
inspectorFrame.addEventListener("mouseover", ()=>{
|
||||
inspectorFrame.focus();
|
||||
});
|
||||
var propnav = document.querySelector("#propnav");
|
||||
function positionInspectorFrame() {
|
||||
var aabb = propnav.getBoundingClientRect();
|
||||
inspectorFrame.style.top = aabb.top + "px";
|
||||
inspectorFrame.style.left = aabb.left + "px";
|
||||
inspectorFrame.style.width = aabb.width + "px";
|
||||
inspectorFrame.style.height = aabb.height + "px";
|
||||
}
|
||||
positionInspectorFrame();
|
||||
var inspectorFrameReposTimer = null;
|
||||
document.body.appendChild(inspectorFrame);
|
||||
@@ -0,0 +1,210 @@
|
||||
PRIMITIVES["item"] = {
|
||||
name: "Item",
|
||||
uses: [],
|
||||
type: "item",
|
||||
tags: {
|
||||
id: "custom_item",
|
||||
name: "Custom Item",
|
||||
texture: VALUE_ENUMS.IMG,
|
||||
firstPersonScale: 1.7,
|
||||
thirdPersonScale: 0.55,
|
||||
useDurationTicks: 32,
|
||||
useItemOnRightClick: true,
|
||||
itemUseAnimation: ["NONE", "EAT", "DRINK", "BLOCK", "BOW"],
|
||||
Constructor: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemConstructor",
|
||||
RightClick: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemRightClick",
|
||||
Used: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemUsed",
|
||||
Tick: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemTicked",
|
||||
UsedOnBlock: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemBlockUse",
|
||||
Crafted: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemCrafted",
|
||||
BlockBroken: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemBlockBroken",
|
||||
GetAttributes: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemGetAttributes",
|
||||
GetEfficiency: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemGetEfficiency",
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
const firstPersonScale = this.tags.firstPersonScale / (flags.target === "1_12" ? 1.7 : 1);
|
||||
const thirdPersonScale = this.tags.thirdPersonScale / (flags.target === "1_12" ? 0.55 : 1);
|
||||
var constructorHandler = getHandlerCode("ItemConstructor", this.tags.Constructor, []);
|
||||
var rightClickHandler = getHandlerCode("ItemRightClick", this.tags.RightClick, ["$$itemstack", "$$world", "$$player"], {
|
||||
"1_8": function (argNames, code) {
|
||||
return `
|
||||
$$CustomItem.prototype.$onItemRightClick = function (${argNames.join(", ")}) {
|
||||
${this.tags.useItemOnRightClick ?
|
||||
`(${argNames[2]}).$setItemInUse(${argNames[0]},${this.tags.useDurationTicks});`
|
||||
: ""}
|
||||
${code};
|
||||
return (${argNames[0]});
|
||||
}
|
||||
`
|
||||
},
|
||||
"1_12": function (argNames, code) {
|
||||
return `
|
||||
var $$ResultEnum = ModAPI.reflect.getClassByName("EnumActionResult").staticVariables;
|
||||
var $$ActionResult = ModAPI.reflect.getClassByName("ActionResult").constructors[0];
|
||||
$$CustomItem.prototype.$onItemRightClick = function (${argNames.slice(1, 3).join(", ")},$handEnum,$unused) {
|
||||
var ${argNames[0]} = (${argNames[2]}).$getHeldItem($handEnum);
|
||||
${this.tags.useItemOnRightClick ?
|
||||
`
|
||||
(${argNames[2]}).$setActiveHand($handEnum);
|
||||
`
|
||||
: ""}
|
||||
${code};
|
||||
return ($$ActionResult(${this.tags.useItemOnRightClick ? "$$ResultEnum.SUCCESS" : "$$ResultEnum.PASS"}, ${argNames[0]}));
|
||||
}
|
||||
`
|
||||
}
|
||||
});
|
||||
var blockUseHandler = getHandlerCode("ItemBlockUse", this.tags.UsedOnBlock, ["$$itemstack", "$$player", "$$world", "$$blockpos"], {
|
||||
"1_8": function (args, code) {
|
||||
return `
|
||||
$$CustomItem.prototype.$onItemUse0 = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return 0;
|
||||
}
|
||||
`
|
||||
},
|
||||
"1_12": function (args, code) {
|
||||
return `
|
||||
var $$ResultEnum = ModAPI.reflect.getClassByName("EnumActionResult").staticVariables;
|
||||
$$CustomItem.prototype.$onItemUse = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return $$ResultEnum.PASS;
|
||||
}
|
||||
`
|
||||
}
|
||||
});
|
||||
var usedHandler = getHandlerCode("ItemUsed", this.tags.Used, ["$$itemstack", "$$world", "$$player"]);
|
||||
var tickedHandler = getHandlerCode("ItemTicked", this.tags.Tick, ["$$itemstack", "$$world", "$$player", "$$hotbar_slot", "$$is_held"]);
|
||||
var craftedHandler = getHandlerCode("ItemCrafted", this.tags.Crafted, ["$$itemstack", "$$world", "$$player"]);
|
||||
var blockBrokenHandler = getHandlerCode("ItemBlockBroken", this.tags.BlockBroken, ["$$itemstack", "$$world", "$$block", "$$blockpos", "$$entity"]);
|
||||
var getAttributes = getHandlerCode("ItemGetAttributes", this.tags.GetAttributes, ["$$attributemap"]);
|
||||
var getEfficiency = getHandlerCode("ItemGetEfficiency", this.tags.GetEfficiency, ["$$itemstack", "$$block"]);
|
||||
|
||||
const transforms = flags.target === "1_12"
|
||||
? {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [0, -90, 55],
|
||||
"translation": [0, 4.0, 0.5],
|
||||
"scale": [0.85 * thirdPersonScale, 0.85 * thirdPersonScale, 0.85 * thirdPersonScale]
|
||||
},
|
||||
"thirdperson_lefthand": {
|
||||
"rotation": [0, 90, -55],
|
||||
"translation": [0, 4.0, 0.5],
|
||||
"scale": [0.85 * thirdPersonScale, 0.85 * thirdPersonScale, 0.85 * thirdPersonScale]
|
||||
},
|
||||
"firstperson_righthand": {
|
||||
"rotation": [0, -90, 25],
|
||||
"translation": [1.13, 3.2, 1.13],
|
||||
"scale": [0.68 * firstPersonScale, 0.68 * firstPersonScale, 0.68 * firstPersonScale]
|
||||
},
|
||||
"firstperson_lefthand": {
|
||||
"rotation": [0, 90, -25],
|
||||
"translation": [1.13, 3.2, 1.13],
|
||||
"scale": [0.68 * firstPersonScale, 0.68 * firstPersonScale, 0.68 * firstPersonScale]
|
||||
}
|
||||
}
|
||||
: {
|
||||
"thirdperson": {
|
||||
"rotation": [-90, 0, 0],
|
||||
"translation": [0, 1, -3],
|
||||
"scale": [thirdPersonScale, thirdPersonScale, thirdPersonScale]
|
||||
},
|
||||
"firstperson": {
|
||||
"rotation": [0, -135, 25],
|
||||
"translation": [0, 4, 2],
|
||||
"scale": [firstPersonScale, firstPersonScale, firstPersonScale]
|
||||
}
|
||||
};
|
||||
|
||||
return `(function ItemDatablock() {
|
||||
const $$itemTexture = "${this.tags.texture}";
|
||||
|
||||
function $$ServersideItem() {
|
||||
const $$scoped_efb_globals = {};
|
||||
var $$itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||
var $$itemSuper = ModAPI.reflect.getSuper($$itemClass, (x) => x.length === 1);
|
||||
var $$itemUseAnimation = ModAPI.reflect.getClassById("net.minecraft.item.EnumAction").staticVariables["${this.tags.itemUseAnimation}"];
|
||||
var $$itemGetAttributes = ModAPI.reflect.getClassById("net.minecraft.item.Item").methods.getItemAttributeModifiers.method;
|
||||
|
||||
function $$CustomItem() {
|
||||
$$itemSuper(this);
|
||||
${constructorHandler.code};
|
||||
}
|
||||
ModAPI.reflect.prototypeStack($$itemClass, $$CustomItem);
|
||||
${rightClickHandler}
|
||||
$$CustomItem.prototype.$getMaxItemUseDuration = function () { //1.12 works
|
||||
return ${this.tags.useDurationTicks};
|
||||
}
|
||||
$$CustomItem.prototype.$getItemUseAction = function () { //1.12 works
|
||||
return $$itemUseAnimation;
|
||||
}
|
||||
$$CustomItem.prototype.$onItemUseFinish = function (${usedHandler.args.join(", ")}) { //1.12 works
|
||||
${usedHandler.code};
|
||||
return (${usedHandler.args[0]});
|
||||
}
|
||||
$$CustomItem.prototype.$onUpdate = function (${tickedHandler.args.join(", ")}) { //1.12 works
|
||||
${tickedHandler.args[4]} = (${tickedHandler.args[4]}) ? true : false;
|
||||
${tickedHandler.code};
|
||||
return (${tickedHandler.args[0]});
|
||||
}
|
||||
|
||||
${blockUseHandler}
|
||||
|
||||
$$CustomItem.prototype.$onCreated = function (${craftedHandler.args.join(", ")}) { //1.12 works
|
||||
${craftedHandler.code};
|
||||
}
|
||||
$$CustomItem.prototype.$onBlockDestroyed = function (${blockBrokenHandler.args.join(", ")}) {
|
||||
${blockBrokenHandler.code};
|
||||
return 0;
|
||||
}
|
||||
$$CustomItem.prototype.$getItemAttributeModifiers = function () { //1.12 works i think
|
||||
var ${getAttributes.args[0]} = $$itemGetAttributes.apply(this, []);
|
||||
${getAttributes.code};
|
||||
return ${getAttributes.args[0]};
|
||||
}
|
||||
$$CustomItem.prototype.$getStrVsBlock = function (${getEfficiency.args.join(", ")}) {
|
||||
${getEfficiency.code};
|
||||
return 1.0;
|
||||
}
|
||||
function $$internal_reg() {
|
||||
var $$custom_item = (new $$CustomItem()).$setUnlocalizedName(
|
||||
ModAPI.util.str("${this.tags.id}")
|
||||
);
|
||||
$$itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("${this.tags.id}"), ModAPI.util.str("${this.tags.id}"), $$custom_item);
|
||||
ModAPI.items["${this.tags.id}"] = $$custom_item;
|
||||
return $$custom_item;
|
||||
}
|
||||
if (ModAPI.items) {
|
||||
return $$internal_reg();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", $$internal_reg);
|
||||
}
|
||||
}
|
||||
|
||||
ModAPI.dedicatedServer.appendCode($$ServersideItem);
|
||||
var $$custom_item = $$ServersideItem();
|
||||
|
||||
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||
ModAPI.addEventListener("lib:asyncsink:registeritems", ($$renderItem)=>{
|
||||
$$renderItem.registerItem($$custom_item, ModAPI.util.str("${this.tags.id}"));
|
||||
});
|
||||
AsyncSink.L10N.set("item.${this.tags.id}.name", "${this.tags.name}");
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"parent": "builtin/generated",
|
||||
"textures": {
|
||||
"layer0": "items/${this.tags.id}"
|
||||
},
|
||||
"display": ${JSON.stringify(transforms)}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/${this.tags.id}.png", await (await fetch(
|
||||
$$itemTexture
|
||||
)).arrayBuffer());
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
PRIMITIVES["metadata"] = {
|
||||
name: "Metadata",
|
||||
uses: [],
|
||||
type: "metadata",
|
||||
tags: {
|
||||
Title: "My Awesome Mod",
|
||||
Version: "v1.0",
|
||||
Description: "Does literally nothing",
|
||||
Credits: "By <author>"
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
return `
|
||||
(function MetadataDatablock() {
|
||||
ModAPI.meta.title("${this.tags.Title.replaceAll('"', '')}");
|
||||
ModAPI.meta.version("${this.tags.Version.replaceAll('"', '')}");
|
||||
ModAPI.meta.description("${this.tags.Description.replaceAll('"', '')}");
|
||||
ModAPI.meta.credits("${this.tags.Credits.replaceAll('"', '')}");
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//TODO: quantityDropped, onBlockDestroyedByExplosion, onBlockActivated
|
||||
PRIMITIVES["ore_generation"] = {
|
||||
name: "Ore Generation",
|
||||
type: "ore_generation",
|
||||
tags: {
|
||||
oreBlock: VALUE_ENUMS.ABSTRACT_BLOCK,
|
||||
lf0: VALUE_ENUMS.NEWLINE,
|
||||
veinSize: 4,
|
||||
veinCount: 105,
|
||||
minGenerationHeight: 0,
|
||||
maxGenerationHeight: 256
|
||||
},
|
||||
getDependencies: function () {
|
||||
const matchesList = new Set([].bake().dynamicConcat("block_advanced", "id", (x) => {
|
||||
return "block/" + x + "@0"
|
||||
}).calculate());
|
||||
const possibleDepsList = new Set([
|
||||
this.tags.oreBlock
|
||||
]);
|
||||
const deps = [...matchesList.intersection(possibleDepsList)].map(x => {
|
||||
x = x.replace("block/", "").split("@");
|
||||
x = x[0];
|
||||
return state.nodes.find(y => (y.type === "block_advanced") && (y.tags.id === x))
|
||||
});
|
||||
return deps;
|
||||
},
|
||||
asJavaScript: function () {
|
||||
var blockId = this.tags.oreBlock.replaceAll("block/", "").split("@")[0];
|
||||
var blockMeta = parseInt(this.tags.oreBlock.replaceAll("block/", "").split("@")[0]) || 0;
|
||||
var salt = "XXXXXX".split("").map(x => Math.floor(Math.random() * 10)).join("");
|
||||
return `(function OreGenerationDatablock() {
|
||||
ModAPI.dedicatedServer.appendCode(()=>{
|
||||
const WorldGenMineable = ModAPI.reflect.getClassById("net.minecraft.world.gen.feature.WorldGenMinable").constructors.find(x=>x.length===2);
|
||||
|
||||
const BiomeDecorator_decorate = ModAPI.util.getMethodFromPackage("net.minecraft.world.biome.BiomeDecorator", "decorate");
|
||||
const oldDecorate = ModAPI.hooks.methods[BiomeDecorator_decorate];
|
||||
ModAPI.hooks.methods[BiomeDecorator_decorate] = function ($this, $world, $random, $biomeGenBase, $blockpos) {
|
||||
if (!$this.$currentWorld) {
|
||||
$this[\`$efb2__${blockId + blockMeta}_${salt}_BlockGen\`] = WorldGenMineable(ModAPI.blocks[\`${blockId}\`].getStateFromMeta(${blockMeta}).getRef(), ${this.tags.veinSize});
|
||||
}
|
||||
return oldDecorate.apply(this, [$this, $world, $random, $biomeGenBase, $blockpos]);
|
||||
}
|
||||
|
||||
const BiomeDecorator_generateOres = ModAPI.util.getMethodFromPackage("net.minecraft.world.biome.BiomeDecorator", "generateOres");
|
||||
const oldGenerateOres = ModAPI.hooks.methods[BiomeDecorator_generateOres];
|
||||
ModAPI.hooks.methods[BiomeDecorator_generateOres] = function ($this) {
|
||||
$this.$genStandardOre1(${this.tags.veinCount}, $this[\`$efb2__${blockId + blockMeta}_${salt}_BlockGen\`] || null, ${this.tags.minGenerationHeight}, ${this.tags.maxGenerationHeight});
|
||||
return oldGenerateOres.apply(this, [$this]);
|
||||
}
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user