cube entity working!

This commit is contained in:
ZXMushroom63 2025-01-28 14:18:41 +08:00
parent b6c5003426
commit bf494e10d3
3 changed files with 35 additions and 18 deletions

View File

@ -58,6 +58,12 @@ ModAPI.meta.credits("By ZXMushroom63");
return true; return true;
} }
AsyncSink.hideFile = function hideFile(path) {
AsyncSink.FSOverride.add(path);
AsyncSink.FS.delete(path);
return true;
}
AsyncSink.getFile = function getFile(path) { AsyncSink.getFile = function getFile(path) {
return AsyncSink.FS.get(path) || new ArrayBuffer(0); return AsyncSink.FS.get(path) || new ArrayBuffer(0);
} }

View File

@ -25,7 +25,7 @@
ModAPI.reflect.implements(nme_EntityCube, IAnimals); ModAPI.reflect.implements(nme_EntityCube, IAnimals);
nme_EntityCube.prototype.$canTriggerWalking = function () { return 0 }; nme_EntityCube.prototype.$canTriggerWalking = function () { return 0 };
nme_EntityCube.prototype.$canBePushed = function () { return 0 }; nme_EntityCube.prototype.$canBePushed = function () { return 1 };
nme_EntityCube.prototype.$getCollisionBox = function () { return this.$getEntityBoundingBox() }; nme_EntityCube.prototype.$getCollisionBox = function () { return this.$getEntityBoundingBox() };
nme_EntityCube.prototype.$getCollisionBoundingBox = function () { return this.$getEntityBoundingBox() }; nme_EntityCube.prototype.$getCollisionBoundingBox = function () { return this.$getEntityBoundingBox() };
nme_EntityCube.prototype.$readEntityFromNBT = function (nbtTagCompount) { // Needed, is an abstract method in parent class nme_EntityCube.prototype.$readEntityFromNBT = function (nbtTagCompount) { // Needed, is an abstract method in parent class
@ -49,12 +49,12 @@
this.$textureWidth = 64; this.$textureWidth = 64;
this.$textureHeight = 64; this.$textureHeight = 64;
this.$cubeRenderer = ModelRenderer(this).$setTextureOffset(0, 0); this.$cubeRenderer = ModelRenderer(this).$setTextureOffset(0, 0);
this.$cubeRenderer.$addBox0(0, 0, 0, 1, 1, 1); this.$cubeRenderer.$addBox0(0, 0, 0, 64, 64, 64);
this.$cubeRenderer.$setRotationPoint(0, 0, 0); this.$cubeRenderer.$setRotationPoint(0, 0, 0);
} }
ModAPI.reflect.prototypeStack(modelBaseClass, nmcm_ModelCube); ModAPI.reflect.prototypeStack(modelBaseClass, nmcm_ModelCube);
nmcm_ModelCube.prototype.$render = function ($entity, useless1, useless2, partialTicks, useless3, useless4, f) { nmcm_ModelCube.prototype.$render = function ($entity, useless1, useless2, partialTicks, useless3, useless4, degToRad) {
this.$cubeRenderer.$render(f); this.$cubeRenderer.$render(degToRad);
} }
// END CUSTOM MODEL // END CUSTOM MODEL
@ -75,12 +75,13 @@
const parentDoRender = nmcre_RenderCube.prototype.$doRender; const parentDoRender = nmcre_RenderCube.prototype.$doRender;
nmcre_RenderCube.prototype.$doRender = function (entity, x, y, z, yaw, pitch) { nmcre_RenderCube.prototype.$doRender = function (entity, x, y, z, yaw, pitch) {
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.translate(x, y + 0.25, z); GlStateManager.translate(x + 0.5, y, z + 0.5);
GlStateManager.rotate(180 - yaw, 0, 1, 0); GlStateManager.rotate(180 - yaw, 0, 1, 0);
this.$bindEntityTexture(entity); GlStateManager.scale(0.25, 0.25, 0.25);
this.$modelCube.$render(entity, 0, 0, -0.1, 0, 0, 0.0625); this.$bindEntityTexture(entity);
GlStateManager.popMatrix(); this.$modelCube.$render(entity, 0, 0, -0.1, 0, 0, 0.0625);
parentDoRender.apply(this, [entity, x, y, z, yaw, pitch]); GlStateManager.popMatrix();
parentDoRender.apply(this, [entity, x, y, z, yaw, pitch]);
} }
const ID = ModAPI.keygen.entity("cube"); const ID = ModAPI.keygen.entity("cube");
ModAPI.reflect.getClassById("net.minecraft.entity.EntityList").staticMethods.addMapping0.method( ModAPI.reflect.getClassById("net.minecraft.entity.EntityList").staticMethods.addMapping0.method(
@ -95,6 +96,7 @@
0x000000, //egg base 0x000000, //egg base
0x00FF00 //egg spots 0x00FF00 //egg spots
); );
// Note that the spawn egg for this will not work, as spawn eggs only spawn entities that are a subclass of EntityLivingBase
console.log(ID); console.log(ID);
ModAPI.addEventListener("lib:asyncsink", async () => { ModAPI.addEventListener("lib:asyncsink", async () => {
@ -117,8 +119,17 @@
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/entity/cube.png", await (await fetch( AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/entity/cube.png", await (await fetch(
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAQBJREFUeF7l0BFzAmAAgOGvKxgMgiAYDIJgEARBEASDQTAIgiAYBEEQBN0NBkEQBEEQBIMgCAZBEAwGgyAIgiAIgiConxE88PJ790RCCNdYCOGeRe/4j4SYDvCgAzzqAHEdIKEDJHWAJx3gWQdI6QBpHeBFB8joAFkdIKcD5HWAgg5Q1AFedYA3HaCkA7zrAGUdoKIDVHWAmg7woQPUdYCGDtDUAVo6QFsH6OgAnzrAlw7Q1QF6OkBfBxjoAEMdYKQDjHWAiQ7wrQNMdYCZDjDXAX50gIUOsNQBVjrArw7wpwP86wBrHWCjA2x1gJ0OsNcBDjrAUQc46QBnHeBiA9wALSueIjTE4PwAAAAASUVORK5CYII=" "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAQBJREFUeF7l0BFzAmAAgOGvKxgMgiAYDIJgEARBEASDQTAIgiAYBEEQBN0NBkEQBEEQBIMgCAZBEAwGgyAIgiAIgiConxE88PJ790RCCNdYCOGeRe/4j4SYDvCgAzzqAHEdIKEDJHWAJx3gWQdI6QBpHeBFB8joAFkdIKcD5HWAgg5Q1AFedYA3HaCkA7zrAGUdoKIDVHWAmg7woQPUdYCGDtDUAVo6QFsH6OgAnzrAlw7Q1QF6OkBfBxjoAEMdYKQDjHWAiQ7wrQNMdYCZDjDXAX50gIUOsNQBVjrArw7wpwP86wBrHWCjA2x1gJ0OsNcBDjrAUQc46QBnHeBiA9wALSueIjTE4PwAAAAASUVORK5CYII="
)).arrayBuffer()); )).arrayBuffer());
AsyncSink.hideFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/entity/cube.png.mcmeta");
ModAPI.mc.renderManager.entityRenderMap.put(ModAPI.util.asClass(data.EntityCube), new data.RenderCube(ModAPI.mc.renderManager.getRef())); ModAPI.mc.renderManager.entityRenderMap.put(ModAPI.util.asClass(data.EntityCube), new data.RenderCube(ModAPI.mc.renderManager.getRef()));
ModAPI.promisify(ModAPI.mc.renderEngine.bindTexture)(data.cubeTexture).then(() => {
console.log("Loaded cube texture into cache.");
});
}); });
console.log(data); console.log(data);
})(); window.temp1 = data;
})();
//var cube_man = new temp1.EntityCube(ModAPI.mc.theWorld.getRef());
//cube_man.$setPosition(-191, 74, 26);
//AsyncSink.startDebugging();
//AsyncSink.startDebuggingFS();
//ModAPI.mc.theWorld.spawnEntityInWorld(cube_man);

View File

@ -1041,9 +1041,9 @@ globalThis.modapi_postinit = "(" + (() => {
ModAPI.util.getBlockFromItem = easyStaticMethod("net.minecraft.block.Block", "getBlockFromItem", true); ModAPI.util.getBlockFromItem = easyStaticMethod("net.minecraft.block.Block", "getBlockFromItem", true);
ModAPI.util.getIdFromBlock = easyStaticMethod("net.minecraft.block.Block", "getIdFromBlock", true); ModAPI.util.getIdFromBlock = easyStaticMethod("net.minecraft.block.Block", "getIdFromBlock", true);
function qhash(txt, arr) { function qhash(txt, arr, interval) {
var interval = 4095; //used to be 4095 - arr.length, but that increases incompatibility based on load order and other circumstances // var interval = 4095; //used to be 4095 - arr.length, but that increases incompatibility based on load order and other circumstances
if (arr.length >= 4095) { if (arr.length >= interval) {
console.error("[ModAPI.keygen] Ran out of IDs while generating for " + txt); console.error("[ModAPI.keygen] Ran out of IDs while generating for " + txt);
return -1; return -1;
} }
@ -1071,15 +1071,15 @@ globalThis.modapi_postinit = "(" + (() => {
} }
ModAPI.keygen.item = function (item) { ModAPI.keygen.item = function (item) {
var values = [...ModAPI.reflect.getClassById("net.minecraft.item.Item").staticVariables.itemRegistry.$modapi_specmap.values()]; var values = [...ModAPI.reflect.getClassById("net.minecraft.item.Item").staticVariables.itemRegistry.$modapi_specmap.values()];
return qhash(item, values); return qhash(item, values, 4095);
} }
ModAPI.keygen.block = function (block) { ModAPI.keygen.block = function (block) {
var values = [...ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry.$modapi_specmap.values()]; var values = [...ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry.$modapi_specmap.values()];
return qhash(block, values); return qhash(block, values, 4095);
} }
ModAPI.keygen.entity = function (entity) { ModAPI.keygen.entity = function (entity) {
var hashMap = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.entity.EntityList").staticVariables.idToClassMapping).getCorrective(); var hashMap = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.entity.EntityList").staticVariables.idToClassMapping).getCorrective();
var values = hashMap.keys.getRef().data.filter(x=>hashMap.get(x)); var values = hashMap.keys.getRef().data.filter(x=>hashMap.get(x));
return qhash(entity, values); return qhash(entity, values, 127);
} }
}).toString() + ")();"; }).toString() + ")();";