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

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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