Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

1.15.I want my block(i'll call it x) to consume whatever block im rightclicking with. i already did the consuming part but if you right click with a block it consumes one and places one next to x. how can i make it so you cant use x to place blocks near it?

Show your code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author
Spoiler

package com.martiblq.washing_mod.events;

import java.util.Random;

import com.martiblq.washing_mod.WashingMod;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@Mod.EventBusSubscriber(modid= WashingMod.MOD_ID, bus = Bus.FORGE, value = Dist.CLIENT)
public class onItemsUsedOnWasherEvent 
{
    @SubscribeEvent
    public static void onItemUsedOnWasherEvent(RightClickBlock event)
    {
        PlayerEntity player = event.getPlayer();
        World world = event.getWorld();
        Block block = world.getBlockState(event.getPos()).getBlock();
        ItemStack heldItemStack = event.getItemStack();
        Item heldItem = heldItemStack.getItem();
        
        int max = 100; 
        int min = 1; 
        int range = max - min + 1;
        
        //gravel
        if (heldItem == Items.GRAVEL && block == Blocks.BEDROCK&& !world.isRemote) 
        {
            //player.inventory.addItemStackToInventory(new ItemStack(Items.DIRT));
            heldItemStack.shrink(1);
            int nugget= (int) (Math.random()*range)+min;
            if(nugget< 11)
            {
                player.inventory.addItemStackToInventory(new ItemStack(Items.GOLD_NUGGET));
            }
            int flint= (int) (Math.random()*range)+min;
            //3
            if(flint>50)
            {
                player.inventory.addItemStackToInventory(new ItemStack(Items.FLINT));
                player.inventory.addItemStackToInventory(new ItemStack(Items.FLINT));
                player.inventory.addItemStackToInventory(new ItemStack(Items.FLINT));
            }
            //2
            else
            {
                player.inventory.addItemStackToInventory(new ItemStack(Items.FLINT));
                player.inventory.addItemStackToInventory(new ItemStack(Items.FLINT));
            }
        }
    }
}

the event

the block

Spoiler

package com.martiblq.washing_mod.objects.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

public class Washer extends Block
{
    public Washer()
    {
        super(Block.Properties.create(Material.WOOD)
        .hardnessAndResistance(2F, 3F)
        .sound(SoundType.WOOD)    
        );
    }
    @Override
    public int getFlammability(BlockState state, IBlockReader world, BlockPos pos, Direction face) 
    {
        return 20;
    }
}
 

i want it so if you rightclick on the block you don't place blocks

Cancel the event.

I believe that that event is one that is cancelable, and if canceled, does not process the placement effect.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.