Jump to content

WhatIsABlock

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by WhatIsABlock

  1. Thank you, that was what was missing. Updated code: @SubscribeEvent public static void onPostDrawOverlay(DrawScreenEvent.Post event){ ... // do some checks to see if the inventory screen is open RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 0.7f); // I set the opacity of the draw here RenderSystem.setShaderTexture(0, RESOURCE_LOCATION); // Do scaling double scaledWidth = ...; double scaledHeight = ...; // Do a blit BufferBuilder builder = tesselator.getBuilder(); builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); builder.vertex(0.0D, scaledHeight, -90.0D).uv(0.0F, 1.0F).endVertex(); builder.vertex(scaledWidth, scaledHeight, -90.0D).uv(1.0F, 1.0F).endVertex(); builder.vertex(scaledWidth, 0.0D, -90.0D).uv(1.0F, 0.0F).endVertex(); builder.vertex(0.0D, 0.0D, -90.0D).uv(0.0F, 0.0F).endVertex(); tesselator.end(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderSystem.disableBlend(); }
  2. I am trying to render a texture as an overlay over the inventory screen - the texture has transparency, but what is drawn in game does not. My render code utilizes DrawScreenEvent.Post, something along the lines of this: @SubscribeEvent public static void onPostDrawOverlay(DrawScreenEvent.Post event){ ... // do some checks to see if the inventory screen is open RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.defaultBlendFunc(); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 0.7f); // I set the opacity of the draw here RenderSystem.setShaderTexture(0, RESOURCE_LOCATION); // Do scaling double scaledWidth = ...; double scaledHeight = ...; // Do a blit BufferBuilder builder = tesselator.getBuilder(); builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); builder.vertex(0.0D, scaledHeight, -90.0D).uv(0.0F, 1.0F).endVertex(); builder.vertex(scaledWidth, scaledHeight, -90.0D).uv(1.0F, 1.0F).endVertex(); builder.vertex(scaledWidth, 0.0D, -90.0D).uv(1.0F, 0.0F).endVertex(); builder.vertex(0.0D, 0.0D, -90.0D).uv(0.0F, 0.0F).endVertex(); tesselator.end(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); } I previously tried the exact same code within the render function of IIngameOverlay, where the opacity rendered as expected. (I didn't use IIngameOverlay because that renders below the inventory) Is there an extra step that I am missing?
  3. Thank you for the example, I really should have seen the obvious getMenu() function. Yes, ItemCraftedEvent is not what I want. Ideally this event would fire after the player either clicks one of the recipes in the recipe book (with all of the needed materials for that recipe), or after the player slots in an item into the crafting matrix that results in a valid craft. My intention is to detect when the crafting matrix has been filled with a valid craft, and submit to the Minecraft instance a TutorialToast. This is part of a student project of mine where I augment the vanilla Tutorial with more instructions on how to play the game.
  4. Hello, I am looking to create an event handler for whenever the crafting matrix of the vanilla Inventory or Crafting Table menu has a valid craft. The way that I had thought about doing that would be by checking if the menu's resultSlot is occupied by something. My idea was to do so through events: call getScreen() from a MouseClickedEvent and check if the screen was InventoryScreen or CraftingScreen. From there I would try to access the menu, but the menu attribute in AbstractContainerScreen is protected, so that is a no-go for me. In short, my questions are: Is there a way of accessing the Menu from an event? Is there a way of telling whether or not there is a valid craft in the crafting matrix?
  5. I experimented and modified the encoder signature to be static: public static void encoder(SyncStatusToClientPacket message, FriendlyByteBuf buffer){ buffer.writeInt(message.tAccessed); buffer.writeInt(message.tCrafted); buffer.writeBoolean(message.hAccessed); buffer.writeBoolean(message.hCrafted); } which did solve the compiler issue. I do want this to be an instance method however - I am still somewhat of a beginner to java, any idea why the compiler doesn't complain about this? ----------EDIT--------- I read about static method references vs instance method references. My final code looks like what warjort posted. Thanks for the help!
  6. Thank you, you were correct that I had imported the wrong Supplier. However, after fixing all instances of the wrongly imported Supplier, the "The type SyncStatusToClientPacket does not define encoder(MSG, FriendlyByteBuf)" error persists even after a clean. I do not import or use any of the other types used by registerMessage() (BiConsumer, Function)
  7. Hello, I am attempting to register my packet: public class SyncStatusToClientPacket{ // Server -> Client message packet to sync the players' status of the tutorial public int tAccessed; public int tCrafted; public boolean hAccessed; public boolean hCrafted; public SyncStatusToClientPacket(int tAccessed, int tCrafted, boolean hAccessed, boolean hCrafted){ this.tAccessed = tAccessed; this.tCrafted = tCrafted; this.hAccessed = hAccessed; this.hCrafted = hCrafted; } public SyncStatusToClientPacket(FriendlyByteBuf buffer){ decoder(buffer); } public static void encoder(SyncStatusToClientPacket msg, FriendlyByteBuf buffer){ buffer.writeInt(msg.tAccessed); buffer.writeInt(msg.tCrafted); buffer.writeBoolean(msg.hAccessed); buffer.writeBoolean(msg.hCrafted); } public static SyncStatusToClientPacket decoder(FriendlyByteBuf buffer){ return new SyncStatusToClientPacket(buffer); } // Sending status to client public static void handle(SyncStatusToClientPacket msg, Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context ctx = supplier.get(); ctx.enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ModClientPacketHandler.handleSyncStatusPacket(msg, supplier)); }); ctx.setPacketHandled(true); } } I am registering it here: public class Messages { private static final String PROTOCOL_VERSION = "1"; public static SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( new ResourceLocation(MCAltTutorial.MODID, "modnetwork"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); private static int packetId = 0; private static int id() { return packetId++; } public static void register(){ // Sync from server to client packet message INSTANCE.registerMessage(id(), SyncStatusToClientPacket.class, SyncStatusToClientPacket::encoder, SyncStatusToClientPacket::decoder, SyncStatusToClientPacket::handle); } } I am getting a compiler error on the line where the method reference for encoder is passed in to registerMessage: The type SyncStatusToClientPacket does not define encoder(MSG, FriendlyByteBuf) that is applicable here I have also attempted to satisfy the BiConsumer parameter by passing in a lambda instead: INSTANCE.registerMessage(id(), SyncStatusToClientPacket.class, (SyncStatusToClientPacket msg, FriendlyByteBuf buf) -> SyncStatusToClientPacket.encoder(msg, buf), ... ); This caused a different error: Incompatible type specified for lambda expression's parameter msg Is the SyncStatusToClientPacket.class argument implicitly passed in, or am I missing something?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.