Jump to content

Recommended Posts

Posted

Today I was trying to make certain features of my mod work with all other mods. I got the first one to work perfectly fine but The second (And last) one has been giving me trouble. I've been trying to get my block to "smelt" whatever you hit it with. (Say one takes iron ore, when the player hits the block while holding the ore it would smelt some it and and drop the corresponding smelting result, which in this case would be iron ingots. This enables it to work with other mods ores and smelting ingredients such as copper! The block is supposed to be an end game item that smelts things way faster than any furnace, if you were wondering) However after I hit it for the first time it doesn't seem to work, as every time I hit it afterwards it doesn't drop anything, but all conditions seem to be met. Hopefully someone here will know what the problem is.

 

 

package mod_Rareores;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class BlockSmeltingBlock extends Block {
        Random generator = new Random();
        @SideOnly(Side.CLIENT)
    private Icon Block_Top;
       
        public BlockSmeltingBlock(int par1) {
                super(par1, Material.iron);
                setCreativeTab(CreativeTabs.tabBlock);
        }
       
       
        public void onBlockClicked(World world, int par2, int par3, int par4, EntityPlayer player) {
               
                ItemStack stack = player.inventory.getCurrentItem();
                int size;
                if(stack==null){
                                player.setFire(4);
                                return;
                }
                if(stack != null && player.inventory.hasItem(Item.coal.itemID)){
                        ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(player.getHeldItem());
                        if(itemstack != null)
                        {
                                size=stack.stackSize;
                                if(size > 8 && size <= 64)
                                {
                                        stack.stackSize -= 8;
                                        if(!world.isRemote)
                                        {
                                       
                                        player.entityDropItem(itemstack, 0.0F);
                                       
                                        }
                                }
                               
                        else
                        {
                                if(!world.isRemote)
                                                {
                                player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
                               
                                        player.entityDropItem(itemstack, 0.0F);
                                                               
                                                }
                                        }
                                }
                        }
                }
       
       
       
        public Icon getIcon(int par1, int par2)
    {
        return par1 == 1 ? this.Block_Top : (this.blockIcon);
    }
       
        public void registerIcons(IconRegister par1IconRegister)
    {
        this.blockIcon = par1IconRegister.registerIcon("Rareores:SmeltSide");
        this.Block_Top = par1IconRegister.registerIcon("Rareores:SmeltTop");
       
    }
}

 

Thanks in advance!

~Noah

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Good idea^^" i know what the problem is.

You are using the wrong function for the RightClicking.

 

It has to be look like this:

public boolean onBlockActivated(World par1, int par2, int par3, int par4, EntityPlayer par5, int par6, float par7, float par8, float par9)
{
     ItemStack item = par5.getCurrentEquippedItem();
     if(item != null && par5.inventory.hasItem(Item.coal.itemID)
     {
          int size = item.getItem().stackSize;
          if(size > 
          {
                 ItemStack output = FurnaceRecipes.smelting().getRecipeOutput(item);
                 if(output != null)
                 {
                        ItemStack realOutput = output;
                        realOutput.stackSize = 8;
                        
                        if(!(par5.inventor.addItemStackToInventory(realOutput)))
                        {
                             par5.entityDropItem(realoutput, 0.0F);
                             par5.getCurrentEquippedItem()getItem().stacksize-=8;
                        }
                        else
                        {
                             par5.addItemStackToInventory(realoutput);
                             par5.getCurrentEquippedItem().getItem().stacksize-=8;
                        }
                 }
          }
     }
     else
     {
          par5.setFire(4);
          return true;
     }
     return true;
}

 

It had to look like this. There could be some mistakes in my code because i wrote it free out of my mind (i am at my mobilephone). But i think that is the way you should go^^"

I hope it helps

Posted

You had it partially right, IT DID need to be onblockactivated but there were other hidden problems within the code that I ended up fixing, but thanks for the help! :D

This is the creator of the Rareores mod! Be sure to check it out at

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, 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 I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders 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
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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