
Recable
Members-
Posts
43 -
Joined
-
Last visited
Everything posted by Recable
-
This code here makes it so that cobblestone instead drops stone if they are wearing the specific pickaxe, however I have found out there's a glitch with this, when a creeper explodes (and the explosion hits the cobblestone) it crashes the game, does anyone know how to fix this? @SubscribeEvent public void addBlockDrop1(HarvestDropsEvent event) { if (event.state.getBlock() == Blocks.cobblestone) { ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem); if (holding != null && holding.getItem() instanceof FirePickaxe) { event.drops.clear(); event.drops.add(new ItemStack(Blocks.stone)); } } } Here's my crash log:
-
Okay thanks.
-
I guess so, but what about the ctrl key? Because I wanted multiple events, one for right click, one for shift + right click, and one for ctrl + right click?
-
Yeah and if they change their sneak key to C for example? Jesus.
-
How do I make it so that inside the onItemRightClick method, you must press, for example, CTRL and right click for the event to happen? I use this code to change blocks that are placed down into another block: @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { worldIn.setBlockState(pos, ModBlocks.AdjustableLightBlockStage1.getDefaultState()); return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ); } else if (Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)){ worldIn.setBlockState(pos, ModBlocks.AdjustableLightBlockFull.getDefaultState()); return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ); } else { return false; } } This works well but I can't seem to get this code: if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { To work inside the onItemRightClick method..? How would I get this to work?
-
How would I make a timer? For example I right click my sword using the onItemRightClick method it then gives me strength 3 for 5 seconds, now how would I make it so this effect won't activate again even when right clicked for 15 seconds?
-
Oh I see thanks.
-
Does anyone know how I would switch an item to another item on right click? So like I wanted to make a twin type of sword so that one sword is more offensive (giving a strength potion effect) and one being more defensive (giving a resistance potion effect) however I know how to do all of the potion effects (I think) and how to create the swords, but what would I do to switch the sword you're currently using with it's other half in the same hot bar slot you had the other sword in?
-
Anyone can help??
-
So far I've made my TnT classes, both the blocks and the entity, using the java code that is, and so for I have it exploding correctly and I can change the radius of the explosion and fuse timer too, so that's perfect, however the texture won't work, and when I light it, it just goes invisible and still blows up after the correct amount of seconds. Here is my Blocks class: package com.TestMod.mod.blocks; import com.TestMod.mod.ModGlobal; import com.TestMod.mod.nukes.ModTestBlockTnt; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraftforge.fml.common.registry.GameRegistry; public class ModBlocks { public static Block TestBlockTnt; public static void initBlocks() { GameRegistry.registerBlock(TestBlockTnt = new ModTestBlockTnt("TestBlockTnt", Material.grass, 0, 0), "TestBlockTnt"); } } Here is my Block Rendering Class: package com.TestMod.mod.render; import com.TestMod.mod.MODGlobal; import com.TestMod.mod.blocks.ModBlocks; import com.TestMod.mod.init.ModBlocks; import com.TestMod.mod.ores.MODOres; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraftforge.fml.common.registry.GameRegistry; public class MODBlockRender { public static void registerBlockRender() { regBlock(ModBlocks.TestBlockTnt); } public static void regBlock(Block block) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(MODGlobal.MOD_ID + ":" + block.getUnlocalizedName().substring(5), "inventory")); } } Here is my Client Proxy: package com.TestMod.mod.proxy; import com.TestMod.mod.blocks.ModBlock; import com.TestMod.mod.blocks.ModBlocks; import com.TestMod.mod.init.ModBlocks; import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; public class ClientProxy extends CommonProxy { public void preInit(FMLPreInitializationEvent preEvent) { super.preInit(preEvent); } public void init(FMLInitializationEvent event) { super.init(event); ModBlockRender.registerBlockRender(); ; ModBlocks.registerRenders(); } @Override public void registerModelBakery() { //Gears ModelBakery.registerItemVariants(Item.getItemFromBlock(ModBlocks.TestBlockTnt), new ResourceLocation ("mod:TestBlockTnt_top")); ModelBakery.registerItemVariants(Item.getItemFromBlock(ModBlocks.TestBlockTnt), new ResourceLocation ("mod:TestBlockTnt_bottom")); ModelBakery.registerItemVariants(Item.getItemFromBlock(ModBlocks.TestBlockTnt), new ResourceLocation ("mod:TestBlockTnt_side")); } public void postInit(FMLPostInitializationEvent postEvent) { super.postInit(postEvent); } } Here is my Blockstate json (Named: ' TestBlockTnt.json '): Here is my Block json (Named: ' TestBlockTnt.json '): Here is my Item json (Named: ' TestBlockTnt.json '):
-
Random random = new Random(); int Chance = random.nextInt(11) + 1; if (Chance == 1) { //Stuff Here } How would I make the above code be: "If chance is equal to 5, to 7 do this." For example I want to set a range of numbers like if the number is from 5 to 8 then do this, how would that be in code wise?
-
Okay thanks but with the list, what would I do to make it the item, the quantity and also the chance of getting that single item? For example: Diamonds, 1 (amount), (20% chance of dropping) Bread, 5 (amount), 50% (chance of dropping) Redstone, 3-7 (amount), 30% (chance of dropping)
-
Why not? It works with what I need, please tell me what the problem is?
-
Thanks for your help, I used a HarvestDropsEvent instead because I already knew how to use that, I just readjusted it to my needs.
-
What would be a good example of a list I need then? And what would I return?
-
@Override public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { Random random = new Random(); int Chance = random.nextInt(4); if (Chance == 1) { return (List<ItemStack>) Items.arrow; } else if (Chance == 2) { return (List<ItemStack>) Items.apple; } else{ return null; } } Okay I did this now but how do I add the drop quantity for each individual item, and also is my current code correct?
-
I should have said this first but I tried using quantityDropped and if I put it to 7, it drops 7 different items rather than 7 diamonds?
-
This code makes it drop different item depending on the random number generated, which is half of what I want, the other half would be making the item it drops be more than if it's stack size is more than one, for example when it drops a diamond I want it to drop 1-5 diamonds and not just one diamond? public Item getItemDropped(IBlockState state, Random random, int fortune) { int Chance = random.nextInt(7) + 1; if (Chance == 1) { return Items.bread; } else if (Chance == 2) { return Items.gold_ingot; } else if (Chance == 3) { return Items.ender_pearl; } else if (Chance == 4) { return Items.diamond; } else if (Chance == 5) { return Items.blaze_rod; } else if (Chance == 6) { return Item.getItemFromBlock(ModBlocks.adjustable_light_block_full); } else if (Chance == 7) { return Item.getItemFromBlock(ModBlocks.ancient_brick_block); } else { return null; } }