Jump to content

Recommended Posts

Posted (edited)

I want to know how to make blocks / objects that are crafted in the world, rather than in the grid. I am talking about the way nether portals and iron golems are crafted in the world by placing blocks. Also doing things like converting blocks with right clicks such as stripping logs with axes.

Edited by MineModder2000
Posted
1 minute ago, MineModder2000 said:

Also doing things like converting blocks with right clicks such as stripping logs with axes.

Check out AxeItem or HoeItem or ShovelItem. They all do it.

 

2 minutes ago, MineModder2000 said:

I am talking about the way nether portals and iron golems are crafted in the world by placing blocks.

I think the iron golems are handled in the Pumpkin blocks class. You'll need to override onBlockPlacedBy in your Blocks class. And if they aren't your blocks you'll need to use an event. I think BlockEvent.Placed? I'm not sure about the name.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
On 9/6/2019 at 10:16 PM, Animefan8888 said:

Check out AxeItem or HoeItem or ShovelItem. They all do it.

 

I think the iron golems are handled in the Pumpkin blocks class. You'll need to override onBlockPlacedBy in your Blocks class. And if they aren't your blocks you'll need to use an event. I think BlockEvent.Placed? I'm not sure about the name.

I see. I've been testing out block conversion on right click with one of my own custom items by copying code from AxeItem. I can get wood / plank / log / stripped blocks to convert from one to another, but it only works for those types, nothing else. I noticed also that minecraft.block package doesn't have any log / wood / plank / stripped blocks in it, so where are they defined? This is what I tried :

 

package mymod.thrown;

import java.util.Map;

import com.google.common.collect.ImmutableMap.Builder;

import mymod.My_Mod;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.RotatedPillarBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class Chert extends Item { // Copies EggItem
	
	protected static final Map<Block, Block> BLOCK_STRIPPING_MAP = new Builder<Block, Block>().put(Blocks.CACTUS, Blocks.JUNGLE_LOG).build();
	
    public Chert(Item.Properties builder) {
	   
        super(builder);
    }

    /**
     * Called to trigger the item's "innate" right click behavior. To handle when this item is used on a Block, see
     * {@link #onItemUse}.
     */
       
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
    	  
    	ItemStack itemstack = playerIn.getHeldItem(handIn);
	    
	    if (playerIn.ticksExisted - My_Mod.tick_last >= 16) {

	    	My_Mod.tick_last = playerIn.ticksExisted;
	    	
	        if (!playerIn.abilities.isCreativeMode) {
	    	   
	            itemstack.shrink(1);
	        }
	
	        worldIn.playSound((PlayerEntity) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
	    	  
	        if (!worldIn.isRemote) {
	        	
			    Chert_Entity chert_entity = new Chert_Entity(worldIn, playerIn);
			    chert_entity.func_213884_b(itemstack);
			    chert_entity.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.15F, 3.0F);
			    worldIn.addEntity(chert_entity);
	        }
	       
	    playerIn.addStat(Stats.ITEM_USED.get(this));
	    
	    return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
      
	    }
	    
	    else return new ActionResult<>(ActionResultType.PASS, itemstack);
   }
    
   public ActionResultType onItemUse(ItemUseContext context) {
	   
	   World world = context.getWorld();
	   BlockPos blockpos = context.getPos();
	   BlockState blockstate = world.getBlockState(blockpos);
	   Block block = BLOCK_STRIPPING_MAP.get(blockstate.getBlock());
	   		
	        if (block != null && !world.isRemote) {
	        	
	            world.setBlockState(blockpos, block.getDefaultState().with(RotatedPillarBlock.AXIS, blockstate.get(RotatedPillarBlock.AXIS)), 11);
	        }
	   
	   return ActionResultType.SUCCESS;
   }
}

 

Edited by MineModder2000
Posted
8 hours ago, diesieben07 said:

You can't do this. This will be shared between all players and break things.

 

This doesn't work, because the original block state (cactus) does not have an axis.

 

Also, use @Override when overriding methods.

 

You'll have to explain the first one more. The whole point of the if statement and tick variables in the onItemRightClick method is to prevent the item from being thrown too rapidly. How else should I do this?

 

Removing with the with() method did the trick, now any blocks can be converted back and forth, thanks. 

Posted
15 minutes ago, MineModder2000 said:

How else should I do this?

Use a Capability or just the ItemStacks NBT tag.

 

16 minutes ago, MineModder2000 said:

You'll have to explain the first one more.

You can't just store a value in the @Mod class and use it for a timer that is player specific like right clicking. There is only one value on the server.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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