Contomman
-
Posts
6 -
Joined
-
Last visited
Posts posted by Contomman
-
-
9 hours ago, nanorover59 said:
Thanks for the help so far!
I was able to render an obsidian block in the world. However, it moves around strangely whenever I stand on a block next to it and sneak or more noticeably if I view it from third person.
The code for the RenderWorldLastEvent that renders the block:
@Mod.EventBusSubscriber(Dist.CLIENT) public class ClientEvents { @SuppressWarnings("deprecation") @SubscribeEvent public static void renderWorldLastEvent(RenderWorldLastEvent event) { if(event.getPhase() != EventPriority.NORMAL) return; Entity entity = Minecraft.getInstance().getRenderViewEntity(); if(entity == null) return; double x = entity.lastTickPosX + (entity.getPosX() - entity.lastTickPosX) * (double) event.getPartialTicks(); double y = entity.lastTickPosY + (entity.getPosY() - entity.lastTickPosY) * (double) event.getPartialTicks(); double z = entity.lastTickPosZ + (entity.getPosZ() - entity.lastTickPosZ) * (double) event.getPartialTicks(); MinecraftServer server = Minecraft.getInstance().getIntegratedServer(); World world = DimensionManager.getWorld(server, DimensionType.OVERWORLD, false, true); MatrixStack matrixStack = event.getMatrixStack(); BlockRendererDispatcher blockRendererDispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); BlockState blockState = Blocks.OBSIDIAN.getDefaultState(); Impl renderTypeBuffer = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer()); matrixStack.push(); matrixStack.translate(-x, -y + 128.0, -z); RenderType renderType = RenderTypeLookup.getRenderType(blockState); blockRendererDispatcher.renderModel(blockState, new BlockPos(0, 128, 0), world, matrixStack, renderTypeBuffer.getBuffer(renderType), false, world.getRandom()); matrixStack.pop(); renderTypeBuffer.finish(); } }
Two screenshots of the rendered block from first and third person perspectives (with a normal diamond block for reference):
I had a very similar problem. What fixes it is replacing
double x = entity.lastTickPosX + (entity.getPosX() - entity.lastTickPosX) * (double) event.getPartialTicks(); double y = entity.lastTickPosY + (entity.getPosY() - entity.lastTickPosY) * (double) event.getPartialTicks(); double z = entity.lastTickPosZ + (entity.getPosZ() - entity.lastTickPosZ) * (double) event.getPartialTicks();
with
Vec3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); matrixStack.translate(-projectedView.x, -projectedView.y+128, -projectedView.z);
(replacing the old matrixStack.translate call in the proper place obviously)
When I had it using .getPartialTicks(), my rendering disappeared while I was moving. Not sure the technical reason behind this, but switching to projectedView works.
-
11 minutes ago, Animefan8888 said:
When registering this way your methods need to be static. And I don't know how I didn't notice that on the first post.
Works Great. Thanks for your patience lol. should have read the docs more carefully
-
24 minutes ago, Animefan8888 said:
Show the actual code you have.
Sure. Here is my Event Handler
package com.example.examplemod.events; import com.example.examplemod.ExampleMod; import net.minecraft.entity.LivingEntity; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.Effects; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.player.ArrowNockEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = ExampleMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class TestEventHandler{ @SubscribeEvent public void onJumpEvent(EntityItemPickupEvent event) { ExampleMod.LOGGER.info("Event Fired"); } }
And here is the main class
package com.example.examplemod; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.stream.Collectors; // The value here should match an entry in the META-INF/mods.toml file @Mod("examplemod") public class ExampleMod { // Directly reference a log4j logger. public static final Logger LOGGER = LogManager.getLogger(); public static final String MODID = "examplemod"; public static ExampleMod instance; public ExampleMod() { instance = this; // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register the enqueueIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); // Register the processIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); // Register the doClientStuff method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { } private void doClientStuff(final FMLClientSetupEvent event) { } private void enqueueIMC(final InterModEnqueueEvent event) { InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); } private void processIMC(final InterModProcessEvent event) { LOGGER.info("Got IMC {}", event.getIMCStream(). map(m->m.getMessageSupplier().get()). collect(Collectors.toList())); } @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { } }
Ive made a (poorly recorded,sorry) video of me building the project and trying to trigger the event, without success. I have tried several events, such as EntityItemPickupEvent and ArrowNockEvent, and I cant get any logger output, system output, potion effects triggering, etc.
This is a newly created mod for the purpose of showing this issue, so there shouldn't be any other interactions I am causing, to the best of my knowledge. -
7 minutes ago, Animefan8888 said:
This even doesn't exist within Minecraft Forge 1.15.2. Did you perhaps mean LivingEvent.LivingJumpEvent?
Sorry about that. Unfortunately I am not getting a result using LivingEvent.LivingJumpEvent either.
I have also tried using EntityItemPickupEvent, as shown in the docs https://mcforge.readthedocs.io/en/latest/events/intro/ -
I have tried many different events and effects in the code below, and I have never gotten the event to fire. The project builds and the client launches without errors. Other aspects of my mod work fine, such as registering new items and blocks with the EventBusSubscriber, so I am not sure why I cant detect other events.
@Mod.EventBusSubscriber(modid = ExampleMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class TestEventHandler{ @SubscribeEvent public void onJumpEvent(PlayerEvent.LivingJumpEvent event) { ExampleMod.LOGGER.info("Event Fired"); LivingEntity livingEntity = event.getEntityLiving(); livingEntity.addPotionEffect(new EffectInstance(Effects.JUMP_BOOST,600,255)); } }
I tried to make a minimum working example, so I made a new mod with only the above class added. For good measure here is the main class, In case I am missing something there. It is mostly Unmodified.
@Mod("examplemod") public class ExampleMod { // Directly reference a log4j logger. public static final Logger LOGGER = LogManager.getLogger(); public static final String MODID = "examplemod"; public static ExampleMod instance; public ExampleMod() { instance = this; // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register the enqueueIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); // Register the processIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); // Register the doClientStuff method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { } private void doClientStuff(final FMLClientSetupEvent event) { } private void enqueueIMC(final InterModEnqueueEvent event) { InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); } private void processIMC(final InterModProcessEvent event) { LOGGER.info("Got IMC {}", event.getIMCStream(). map(m->m.getMessageSupplier().get()). collect(Collectors.toList())); } @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { } }
Here is my latest log file. I didnt see anything out of the ordinary in it
https://pastebin.com/2L3gdHrE
***SOLVED EDIT***I did not make my method static, which Is required to automatically register the class without passing the eventbus an instance of the class, as outlined in https://mcforge.readthedocs.io/en/latest/events/intro/.
[1.15.2] IRenderTypeBuffer for use with RenderWorldLastEvent
in Modder Support
Posted · Edited by Contomman
Im not quite sure how do do that either, im working on a different bit of my mod right now, but I know if you look at the code for defining the RenderType you can give it variables for lighting (there is one called lightmap), but I havent tried changing it yet. That part of the code doesnt seem to be fully mapped out yet, even on the latest mappings, so there is still alot of obfuscated variables. Let me know If you get it working. Ill message you if I ever get that far.