Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4] Custom Anvil Help


vassdeniss
 Share

Recommended Posts

I am trying to create a custom anvil for my mod and the approach i am trying is to create a normal vanilla anvil with custom recipe container - i tried creating the block and passing a custom container to it but i do feel a bit stuck and confused on how to do this. Some explanation and guidence would be great! Thanks in advance.

package com.vassdeniss.makoru.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.IWorldPosCallable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

public class AngelAnvilBlock extends Block {
    private static final ITextComponent AngelAnvilContainer = new TranslationTextComponent("container.crafting");

    public AngelAnvilBlock() {
        super(Block.Properties.create());
    }

    @Override
    public ActionResultType onBlockActivated(BlockState p_225533_1_, World worldIn, BlockPos p_225533_3_, PlayerEntity player, Hand p_225533_5_, BlockRayTraceResult p_225533_6_) {
        if (worldIn.isRemote) {
            return ActionResultType.SUCCESS;
        } else {
            NetworkHooks.openGui(player, );
            player.addStat(Stats.INTERACT_WITH_ANVIL);
            return ActionResultType.CONSUME;
        }
    }

    @Override
    public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos)  {
        return new SimpleNamedContainerProvider((id, inventory, player) -> new AngelAnvilContainer(id, inventory, IWorldPosCallable.of(world, pos)),
                AngelAnvilContainer);
    }
}
package com.vassdeniss.makoru.blocks;

import com.vassdeniss.makoru.util.RegistryHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.RepairContainer;
import net.minecraft.util.IWorldPosCallable;

public class AngelAnvilContainer extends RepairContainer {
    private final IWorldPosCallable field_217070_e;

    public AngelAnvilContainer(int id, PlayerInventory playerInventory, IWorldPosCallable p_i50102_3_) {
        super(id, playerInventory, p_i50102_3_);
        this.field_217070_e = p_i50102_3_;
    }

    @Override
    public boolean canInteractWith(PlayerEntity player) {
        return isWithinUsableDistance(this.field_217070_e, player, RegistryHandler.ANGEL_ANVIL.get());
    }
}

 

Link to comment
Share on other sites

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.