Jump to content

Understanding transferStackInSlot method


TheEpicTekkit

Recommended Posts

Hello.

 

I would like help understanding the unnecessarily complicated and undocumented method:

transferStackInSlot(EntityPlayer player, int slotIndex)

I have looked around for tutorials on how to use this method, and only found things like a custom furnace, which has pretty much the exact same code as the vanilla furnace, and a badly explained transferStackInSlot method. I have also looked at the code of some mods such as EnderIO on Github and just found more confusion.

 

I think that the best documentation on transferStackInSlot that I have found is this.

 

What I would like is for someone to explain this method and how to implement it. I want to actually understand the code, and not have a tutorial that tells me what to write with no explanation, like a lot of tutorials do. I understand that the EntityPlayer parameter is the player using the inventory (obviously), the slotIndex is the slot that was shift-clicked, and the methods goal is to handle shift-clicking of slots, but I don't understand things like the mergeItemStack method, what the ItemStack that transferStackInSlot returns represents, or how to implement this method.

 

Furthermore, if I can understand this method properly, I would like to be able to implement a generic version of this method that automatically works for all containers. EnderIO seems to have it setup this way. But currently, I am trying to implement this for a machine with one input slot, 3 output slots, and a battery slot.

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Thanks for this. I haven't had much time to read through this method, but it looks pretty nice. Though I am looking for an explanation of how the transferStackInSlot method works and how it is used. I don't want to just have code to copy and paste, because I wont learn anything from that.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Not to sound rude (seriously) but there is nothing that's gonna explain (this particular) method better than reading it and its callbacks. You'd be better off just analysing it. My guess is that anyone who'd attempt to "explain" it, when diesieben alredy gave you self-explainatory code would end up with something like this (which won't really help): :D

/** Moves Element e to Collection C. */
public void moveElementToCollection(Element e, Collection C)
{ ... }

 

Unless you are asking about Containers, Inventories and Slots themselves, then that would be a totally different answer or should I say - essay (there is a lot to talk about). :)

 

But, since it's support, where lies the problem?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Here's the link: https://mclo.gs/7L5FibL Here's the link: https://mclo.gs/7L5FibL
    • Also the mod "Connector Extras" modifies Reach-entity-attributes and can cause fatal errors when combined with ValkrienSkies mod. Disable this mod and continue to use Syntra without it.
    • Hi everyone. I was trying modify the vanilla loot of the "short_grass" block, I would like it drops seeds and vegetal fiber (new item of my mod), but I don't found any guide or tutorial on internet. Somebody can help me?
    • On 1.20.1 use ValkrienSkies mod version 2.3.0 Beta 1. I had the same issues as you and it turns out the newer beta versions have tons of unresolved incompatibilities. If you change the version you will not be required to change the versions of eureka or any other additions unless prompted at startup. This will resolve Reach-entity-attributes error sound related error and cowardly errors.
  • Topics

×
×
  • Create New...

Important Information

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