# than00ber1

Members

34

1

1. ## [1.19] Screen point (x,y) to world coordinates (x,y,z)

Hi there I am attempting to make a gui where the player will be able to click whatever block is in front of them. I've tried a few approaches and none of them have worked. (Bare with me as I have absolutely zero knowledge in 3D rendering.) I've looked online for a bit and found this on stackoverflow using OpenGL. Here is my 1:1 attempt in Java on my container screen: @Override public void render(@NotNull PoseStack pose, int mouseX, int mouseY, float partialTick) { // https://stackoverflow.com/a/7702895/13844398 // STEP 1: get mouse coords. (mouseX, mouseY) // STEP 2 Matrix4f modelviewMatrix = RenderSystem.getModelViewMatrix(); Matrix4f projectionMatrix = RenderSystem.getProjectionMatrix(); // STEP 3 modelviewMatrix.multiply(projectionMatrix); // STEP 4 modelviewMatrix.invert(); // STEP 5 float x = Mth.clampedMap(mouseX, 0.0F, width, -1.0F, 1.0F); float y = Mth.clampedMap(mouseY, 0.0F, height, -1.0F, 1.0F); float z = 1.0F; // the depth value ? float w = 1.0F; Vector4f vector4f = new Vector4f(x, y, z, w); // STEP 6 vector4f.transform(modelviewMatrix); // STEP 7 vector4f.mul(1 / vector4f.w()); // presumably results in a direction vector ?? Vec3 vec3 = new Vec3(vector4f.x(), vector4f.y(), vector4f.z()); getMinecraft().font.draw(pose, vec3.toString(), 10.0F, 10.0F, 14737632); } My screen prints something that resembles this: (239.75..., 126.00..., -2003000.125). Which simply looks like my cursor's coordinates (with an extra`z` value) on screen an nothing more. Am I heading towards the right direction? Is there an easier way?
2. ## Forge 39.1.0 MDK | java.lang.NoClassDefFoundError: Could not initialize class com.mojang.blaze3d.systems.RenderSystem

I run into the same issue when using 1.18.2. I switched IDE too but to no avail. Could it from the java version I am using?

4. ## [1.17.x] Replacing/extending functions from vanilla class

Mixins? https://github.com/SpongePowered/Mixin/wiki/Introduction-to-Mixins---Understanding-Mixin-Architecture#2-through-the-looking-glass
5. ## How to get/check player hp

Alright. the FMLClientSetupEvent is not the corret event to listen to (at all). You will need to listen for the PlayerTickEvent event. public class PlayerTickHandler { @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { PlayerEntity player = event.player; if (player.getHealth() < 7) { player.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 60)); } } } And register it for Forge event bus inside your mod's construcor like this: MinecraftForge.EVENT_BUS.register(new PlayerTickHandler()); Note the @SubscribeEvent, this essentially tells forge that the methods is listening for an event.
6. ## .

What do you not get? Are there any error logs you can show? What do you mean by "no forge practice on my forge file folder"?
7. ## Help discerning crash report

The mod causing this error is Extra Anvils. The error occurs because of how the mod gives a rainbow effect to text with some timing trickery. I believe this could be OS-related.

9. ## [1.16.4] ModelBakeEvent Event Listener Not Triggered

Noted. I am trying to fetch Fence blocks and add an overlay to it. By you mean ICustomModelLoader?

11. ## Data Gen - Block Model from JSON template throws error

Ok, found the issue. Within ModelBuilder, there are a few different method signatures for texture. Of which: public T texture(String key, String texture) : T and public T texture(String key, ResourceLocation texture) : T Method 1 uses <key> as the JSON key and <texture> as the asset path while in Method 2 <key> as the asset path and <texture> as the JSON key. Since I used the first method before and it my code worked, I assumed it was the same for the second method. Their paramaters are effectively swapped and this confused the hell out of me. In hindsight, I should read the comments more...
12. ## Data Gen - Block Model from JSON template throws error

I am trying to generate my block models with Data Generators which I incounter this error: Invalid ResourceLocation block/minecraft:sand It's easy to spot why this error occurs ("block/minecraft:sand", ':' triggers the error) but I don't understand where this error could come from by looking at my code. Since I have a few variants of the same block, I've replicated Minecraft's way by defining a template JSON for my variant and simply have my block use it as a parent and add a texture. Heres what I have: private void generateSiltBlockFenceGateFromTemplate(SiltFenceGateBlock gate) { String texture = Objects.requireNonNull(gate.getParentBlock().getRegistryName()).toString(); getVariantBuilder(gate).forAllStatesExcept(state -> { String base = "silt_fence_gate" + (state.get(OPEN) ? "_open_" : "_close_") + state.get(AbstractSiltBarrierBlock.LAYER); if (state.get(IN_WALL)) base = base + "_in_wall"; // <base> would look like "silt_fence_gate_close_1" ModelBuilder<?> model = models() .withExistingParent(texture + "_" + base, modLoc("block/template_" + base)) .texture("texture", mcLoc("block/" + texture)) // <--- stacktrace points here .element().end(); int rotation = (int) state.get(HORIZONTAL_FACING).getHorizontalAngle(); return ConfiguredModel.builder().modelFile(model).uvLock(true).rotationY(rotation).build(); }, WATERLOGGED ); } I've also tried to feed it a texture as a string directly but to no avail: .texture("texture", "block/" + texture) // <--- stacktrace points here What I expect is sand_silt_fence_gate_close_1.json: { "parent": "siltsand:block/template_silt_fence_gate_close_1" "textures": { "texture": "sand" } } Here's my template JSON: template_silt_fence_gate_close_1.json: { "parent": "block/block", "textures": { "particle": "#texture" }, "elements": [ { "from": [ 14, 0, 7 ], "to": [ 16, 1, 9 ], "faces": { "north": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "up": { "uv": [ 0, 0, 2, 2 ], "texture": "#texture" } } }, { "from": [ 0, 0, 7 ], "to": [ 2, 1, 9 ], "faces": { "north": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "up": { "uv": [ 0, 0, 2, 2 ], "texture": "#texture" } } }, { "from": [ 2, -1, 7 ], "to": [ 14, 0, 9 ], "faces": { "up": { "uv": [ 0, 0, 12, 2 ], "texture": "#texture" }, "north": { "uv": [ 0, 0, 12, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 12, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" } } }, { "from": [ 10, -7, 7 ], "to": [ 14, -6, 9 ], "faces": { "up": { "uv": [ 0, 0, 4, 2 ], "texture": "#texture" }, "north": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" } } }, { "from": [ 2, -7, 7 ], "to": [ 6, -6, 9 ], "faces": { "up": { "uv": [ 0, 0, 4, 2 ], "texture": "#texture" }, "north": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" } } } ] } I have read that maybe this might be caused by invalid JSON but that has been checked too. Any idea why this happens? PS: I am new to Data Gens so it is very likely that I using the builder wrong. PPS: Posted my issue in the wrong topic section
13. ## Data Gen - Block Model from JSON template throws error

I am trying to generate my block models with Data Generators which I incounter this error. It's easy to spot why this error occurs ("block/minecraft:sand", ':' triggers the error) but I don't understand where this error could come from by looking at my code. Since I have a few variants of the same block, I've replicated Minecraft's way by defining a template JSON for my variant and simply have my block use it as a parent and add a texture. Heres what I have: private void generateSiltBlockFenceGateFromTemplate(SiltFenceGateBlock gate) { String texture = Objects.requireNonNull(gate.getParentBlock().getRegistryName()).toString(); getVariantBuilder(gate).forAllStatesExcept(state -> { String base = "silt_fence_gate" + (state.get(OPEN) ? "_open_" : "_close_") + state.get(AbstractSiltBarrierBlock.LAYER); if (state.get(IN_WALL)) base = base + "_in_wall"; // <base> would look like "silt_fence_gate_close_1" ModelBuilder<?> model = models() .withExistingParent(texture + "_" + base, modLoc("block/template_" + base)) .texture("texture", mcLoc("block/" + texture)) // <--- stacktrace points here .element().end(); int rotation = (int) state.get(HORIZONTAL_FACING).getHorizontalAngle(); return ConfiguredModel.builder().modelFile(model).uvLock(true).rotationY(rotation).build(); }, WATERLOGGED ); } I've also tried to feed it a texture as a string directly but to no avail: .texture("texture", "block/" + texture) // <--- stacktrace points here What I expect is sand_silt_fence_gate_close_1.json: { "parent": "siltsand:block/template_silt_fence_gate_close_1" "textures": { "texture": "sand" } } Here's my template JSON: template_silt_fence_gate_close_1.json: { "parent": "block/block", "textures": { "particle": "#texture" }, "elements": [ { "from": [ 14, 0, 7 ], "to": [ 16, 1, 9 ], "faces": { "north": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "up": { "uv": [ 0, 0, 2, 2 ], "texture": "#texture" } } }, { "from": [ 0, 0, 7 ], "to": [ 2, 1, 9 ], "faces": { "north": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "up": { "uv": [ 0, 0, 2, 2 ], "texture": "#texture" } } }, { "from": [ 2, -1, 7 ], "to": [ 14, 0, 9 ], "faces": { "up": { "uv": [ 0, 0, 12, 2 ], "texture": "#texture" }, "north": { "uv": [ 0, 0, 12, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 12, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" } } }, { "from": [ 10, -7, 7 ], "to": [ 14, -6, 9 ], "faces": { "up": { "uv": [ 0, 0, 4, 2 ], "texture": "#texture" }, "north": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" } } }, { "from": [ 2, -7, 7 ], "to": [ 6, -6, 9 ], "faces": { "up": { "uv": [ 0, 0, 4, 2 ], "texture": "#texture" }, "north": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "south": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" }, "west": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }, "east": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" } } } ] } I have read that maybe this might be caused by invalid JSON but that has been checked too. Any idea why this happens? PS: I am new to Data Gens so it is very likely that I using the builder wrong.
14. ## [1.16.4] Tick Event listener for non-living entities

I am trying to listen for vanilla minecarts on every tick. In the past I would use `MinecartUpdateEvent` but in the newer version this seems to have been removed. Instead, I tried to listen for `EntityEvent#CanUpdate()` but this event is never called: https://github.com/MinecraftForge/MinecraftForge/issues/6394 Is there an alternative to listening for vanilla minecart on every tick?
15. ## [1.16.4] Set EntitySize fixed for Entities

I am trying to set my entity's EntitySize fixed. I can set the entity's size with EntityType.Builder::size(float, float) which this calls EntitySize::flexible(float, float) but the builder does not seem to have a method with EntitySize::fixed(float, float) for setting fixed entity sizes. I figured I could make my own entity builder but that seems overkill just for this. Is there a better way to set an entity's size as fixed?
16. ## [1.16.4] Passing cart entity down to container constructor

Haha your right, it looks stupid.
17. ## [1.16.4] Passing cart entity down to container constructor

Alright it works now, heres what I did to make it work. On the entity's side I call open the container like this: @Override public ActionResultType processInitialInteract(PlayerEntity player, Hand hand) { if (!player.world.isRemote()) { NetworkHooks.openGui((ServerPlayerEntity) player, this, b -> b.writeInt(this.getEntityId())); } return ActionResultType.SUCCESS; } @Override public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); buffer.writeInt(this.getEntityId()); return new ContainerModuleCartMiner(id, playerInventory, buffer); } Where I assign the entity's id to a buffer and in the container: public ContainerModuleCartMiner(int id, PlayerInventory playerInventory, PacketBuffer buffer) { super(ContainerRegistry.MINER_CART_CONTAINER.get(), id); Entity entity = playerInventory.player.world.getEntityByID(buffer.readInt()); if (entity instanceof EntityModuleCartMiner) System.out.println(playerInventory.player.world.isRemote()); // outputs both 'ture' & 'false', meaning both client and server managed to get the entity from the buffer int } Edit: Is it ever possible for the packetbuffer to be null?
18. ## [1.16.4] Passing cart entity down to container constructor

I am trying to pass down my cart entity instance down to my container. I've tried a few different things which worked but never with the correct constructor paramaters (with my entity class). Heres how register my container, public static final RegistryObject<ContainerType<ContainerModuleCartMiner>> MINER_CART_CONTAINER = CONTAINERS.register("miner_module_cart", () -> new ContainerType(ContainerModuleCartMiner::new)); and call it like this within my entity class: // Entity class implements `IInventory` and `INamedContainerProvider` // server side? @Override public ActionResultType processInitialInteract(PlayerEntity player, Hand hand) { if (!player.world.isRemote()) NetworkHooks.openGui((ServerPlayerEntity) player, this); return ActionResultType.SUCCESS; } // client side? @Override public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { return new ContainerModuleCartMiner(id, playerInventory, this); } And my container looks like this: // constr. 1 public ContainerModuleCartMiner(int id, PlayerInventory playerInventory) { this(id, playerInventory, new Inventory(0)); } // constr. 2 public ContainerModuleCartMiner(int id, PlayerInventory playerInventory, IInventory inventory) { super(ContainerRegistry.MINER_CART_CONTAINER.get(), id); if (inventory instanceof EntityModuleCartMiner) System.out.println(playerInventory.player.world.isRemote) // outputs: false, client only this.loadPlayerInventory(playerInventory, ScreenModuleCartMiner.SIZE_X, ScreenModuleCartMiner.SIZE_Y); } The first constructor gets called on the server side which subsequently calls the second constructor with an empty inventory, only on the client side does the second constructor get called (from my understanding). Checking whether `inventory` is an instance of my entity only works in the client and not on the server. Is there a way to call the same constructor on both the client/server side with params `int`, `PlayerInventory` and `Entity` instead of `IInventory`directly? Also, I've tried calling the constructor with `int`, `PlayerInventory` and `PacketBuffer` and pass int the Entity's id along and retreive it on the other end with `world.getEntityById(buffer.readInt())` but it always seem to be null.
19. ## [Solved[[1.16.1] Getting Entity from PacketBuffer

How did you solve it @DavidQF555?
20. ## [1.16.4] Registering EntityRenders returns errors

I was able to solve the issue by rewriting all classes (must have gotten a class extending the wrong thing I think) but why shouldn't I use @OnlyIn on the renderers? Isn't it just client-side? Edit: Should I remove all @OnlyIn?
21. ## [1.16.4] Registering EntityRenders returns errors

I've been trying to register my cart entity to `RenderingRegistry`but I have been receiving errors I am having a hard time understanding. I register my entity renderer like this: public static void registerRenderers(final FMLClientSetupEvent event) { RenderingRegistry.registerEntityRenderingHandler(AllEntities.MINER_CART_ENTITY.get(), MinerModuleCartRenderer::new); } and this is my MinerModuleCartRenderer: @OnlyIn(Dist.CLIENT) public class MinerModuleCartRenderer<T extends AbstractMinecartEntity> extends EntityRenderer<T> { private static final ResourceLocation MINER_TEXTURE = new ResourceLocation(MODID + ":textures/entity/miner_cart_module.png"); private final EntityModel<T> modelCartModule = new MinerCartModuleModel<>(); public MinerModuleCartRenderer(EntityRendererManager renderManager) { super(renderManager); } public void render(T entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) { // [...] long code copied from MinecartRenderer directly } public ResourceLocation getEntityTexture(T entity) { return MINER_TEXTURE; } protected void renderBlockState(T entity, float partialTicks, BlockState state, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) { Minecraft.getInstance().getBlockRendererDispatcher().renderBlock(state, matrixStack, buffer, packedLight, OverlayTexture.NO_OVERLAY); } } but I get this error: Bad return type in method reference: cannot convert com.than00ber.gameoflife.client.renderer.entity.MinerModuleCartRenderer<T> to net.minecraft.client.renderer.entity.EntityRenderer<? super ?> (I get the same error when trying to register Minecraft's `MinercartRenderer` like this) I've looked into Minecraft 's source code and noticed that it registers its entity renderers like this: public <T extends Entity> void register(EntityType<T> entityTypeIn, EntityRenderer<? super T> entityRendererIn) { this.renderers.put(entityTypeIn, entityRendererIn); } but Forge with `IRenderFactory`: public static <T extends Entity> void registerEntityRenderingHandler(EntityType<T> entityClass, IRenderFactory<? super T> renderFactory) { INSTANCE.entityRenderers.put(entityClass, renderFactory); } so I implemented `IRenderFactorty` in `MinerModuleCartRenderer` to see if it makes a difference but to no avail; the error stays the same. Any idea why that is and how can I solve this? Now I know this is more of Java error but I figured I'll get a better shot here since people have prior knowledge.
22. ## [1.16.4] How do you register a custom minecart entity?

Ah I managed to do this. The problem was really dumb, I didn't register the actual item itself. For any in the future that want to know how to it, this how I did it: Create the item: public class MinerCartItem extends MinecartItem { public MinerCartItem() { super(AbstractMinecartEntity.Type.RIDEABLE, (new Item.Properties()).maxStackSize(1).group(ItemGroup.FOOD)); } } and then register it the same way you would do for other registries: public static final RegistryObject<Item> MINER_ITEM = ITEMS.register("miner_item", MinerCartItem::new);
23. ## [1.16.4] How do you register a custom minecart entity?

Where would I call this? NetworkHooks.getEntitySpawningPacket(this) In the constructor of the minecart class?
24. ## [1.16.4] How do you register a custom minecart entity?

I am trying to register a simple minecart entity but it does not seem to appear in-game. No errors are thrown either. Here is my Minecart entity class: public class MinerCartEntity extends AbstractMinecartEntity { public MinerCartEntity(EntityType<?> type, World worldIn) { super(type, worldIn); } @Override public Type getMinecartType() { return Type.CHEST; } } Here is how I register it, public class AllEntities { public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, MODID); private static <T extends EntityType<?>> RegistryObject<EntityType<?>> register(String name, Supplier<T> entity) { System.out.println("REGISTERING MOD ENTITY: " + name); return ENTITIES.register(name, entity); } public static final RegistryObject<EntityType<?>> MINER_MINECART = register("miner_minecart", () -> EntityType.Builder.<AbstractMinecartEntity>create(MinerCartEntity::new, EntityClassification.MISC) .size(0.98F, 0.7F).trackingRange(8) .build(new ResourceLocation(MODID, "miner_minecart").toString())); } and in the main file simply: IEventBus fmlContext = FMLJavaModLoadingContext.get().getModEventBus(); AllBlocks.BLOCKS.register(fmlContext); AllTileEntities.TILE_ENTITIES.register(fmlContext); AllItems.ITEMS.register(fmlContext); AllEntities.ENTITIES.register(fmlContext); // <------ over here My first guess was to follow the same way to register entities as blocks or items while using the entity builder shown in Minecraft's source code. Any guess as to why it does not load in-game or not throwing errors? Is this even the right way?
25. ## How to effectively port a mod to other game versions?

Yeah I am aware of that. Thanks for your respons, this helps a tone!
×

• #### Activity

×
• Create New...