Jump to content

X_Khan_X

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by X_Khan_X

  1. Hello, I've created some .nbt files using a structure block and I use public class StructureGenHelper extends WorldGenerator implements IStructure { public String structureName; public StructureGenHelper(String name) { structureName = name; } @Override public boolean generate(World worldIn, Random rand, BlockPos position) { generateStructure(worldIn, position); return true; } public boolean generateStructure(World world, BlockPos pos) { MinecraftServer mcServer = world.getMinecraftServer(); TemplateManager manager = worldServer.getStructureTemplateManager(); ResourceLocation location = new ResourceLocation(Main.MODID, structureName); Template template = manager.get(mcServer, location); if (template == null) { Messages.serverLog(Main.logger, "The structure " + structureName + " doesn't exist!", 3); } if (template != null) { IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); template.addBlocksToWorldChunk(world, pos, settings); return true; } return false; } } to generate a structure but I have a problem to rotate the structure based where the player is facing, can someone help me or point me to the right direction? Thanks
  2. The suppress warning is useless, need to remove the state. The line 30 is the hand item Edit: System.out.print(event.getHarvester()); prints me and null at the same time
  3. I have an autosmelt class public class AutosmeltEvent { @SubscribeEvent(priority = EventPriority.LOW) public static void onAutosmeltUse(HarvestDropsEvent event) { EntityPlayer player = (EntityPlayer) event.getHarvester(); ItemStack hand = player.inventory.getCurrentItem(); Map<Enchantment, Integer> autosmelt = EnchantmentHelper.getEnchantments(hand); if (autosmelt.isEmpty() || !autosmelt.containsKey(InitEnchants.AUTOSMELT)) return; int autosmeltlevel = autosmelt.get(InitEnchants.AUTOSMELT); Block block = event.getState().getBlock(); @SuppressWarnings("unused") IBlockState state = event.getState(); World world = event.getWorld(); BlockPos pos = event.getPos(); ItemStack smelt = FurnaceRecipes.instance().getSmeltingResult(new ItemStack(block)); smelt.setCount(1); ItemStack out = smelt.copy(); if (autosmeltlevel == 1) { if (smelt.getItem() == Item.getItemFromBlock(Blocks.AIR) && !player.capabilities.isCreativeMode) { world.destroyBlock(pos, true); } if (block != null) { world.setBlockToAir(pos); event.getDrops().clear(); event.getDrops().add(out); player.addExperience(1); } } } } that works with the enchant and an excavate class public class ExcavateEvent { @SubscribeEvent(priority = EventPriority.NORMAL) public static void onExcavateUse(BlockEvent.BreakEvent event) { EntityPlayer player = (EntityPlayer) event.getPlayer(); ItemStack hand = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND); Map<Enchantment, Integer> excavate = EnchantmentHelper.getEnchantments(hand); if (excavate.isEmpty() || !excavate.containsKey(InitEnchants.EXCAVATE)) return; int excavatelevel = excavate.get(InitEnchants.EXCAVATE); World world = event.getWorld(); BlockPos pos = event.getPos(); Block block = event.getState().getBlock(); if (excavatelevel > 0) { for (int i = 0; i < (excavatelevel + 1); i++) { Iterable<BlockPos> it = BlockPos.getAllInBox(pos.add(-i, -i, -i), pos.add(i, i, i)); for (BlockPos offset2 : it) { Block block2 = world.getBlockState(offset2).getBlock(); if (block2 == block && block2 != Blocks.AIR) { try { world.destroyBlock(offset2, true); hand.damageItem(1, player); } catch (Exception e) { e.printStackTrace(); } } } } } } } which gives me problems when I use the excavate enchant (without autosmelt on the pickaxe) java.lang.NullPointerException: null at com.mod.modcore.events.enchantment.AutosmeltEvent.onAutosmeltUse(AutosmeltEvent.java:30) ~[AutosmeltEvent.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_17_AutosmeltEvent_onAutosmeltUse_HarvestDropsEvent.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?] at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:321) [ForgeEventFactory.class:?] at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:721) [Block.class:?] at net.minecraft.block.BlockOre.dropBlockAsItemWithChance(BlockOre.java:92) [BlockOre.class:?] at net.minecraft.block.Block.dropBlockAsItem(Block.java:710) [Block.class:?] at net.minecraft.world.World.destroyBlock(World.java:477) [World.class:?] at com.mod.modcore.events.enchantment.ExcavateEvent.onExcavateUse(ExcavateEvent.java:42) [ExcavateEvent.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_ExcavateEvent_onExcavateUse_BreakEvent.invoke(.dynamic) [?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) [ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?] at net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(ForgeHooks.java:838) [ForgeHooks.class:?] at net.minecraft.server.management.PlayerInteractionManager.tryHarvestBlock(PlayerInteractionManager.java:309) [PlayerInteractionManager.class:?] at net.minecraft.server.management.PlayerInteractionManager.blockRemoving(PlayerInteractionManager.java:261) [PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:732) [NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) [CPacketPlayerDigging.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) [CPacketPlayerDigging.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) [PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_221] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_221] at net.minecraft.util.Util.runTask(Util.java:53) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_221] I know, the solution may be very very simple but I dont know why it throw me an error when breaking blocks AutosmeltEvent line 30: ItemStack hand = player.inventory.getCurrentItem(); ExcavateEvent line 42: world.destroyBlock(offset2, true);
  4. Tried and in a 125 blocks test (5x5x5 cube) it dropped me 64+61 iron ore which is correct but it doesn't have to drop them and 7 stacks and 56 iron ingots
  5. Hello, I'm trying to create a custom enchant "Autosmelt" but sometimes it drops me more than one item, this occurs more when haste is applied, giving me 2 or more items when a block is broken. I've tested it with haste 30 (only to oneshot the blocks) with a vanilla diamond pickaxe (autosmelt enchant only) and a 5x5 iron ore block, giving me like 6 stacks of iron ingots. How can I set it drop only 1 item per block? Is the smelt result correct/good? @SubscribeEvent public static void onAutosmeltUse(BlockEvent.BreakEvent event) { EntityPlayer player = (EntityPlayer) event.getPlayer(); ItemStack head = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND); Map<Enchantment, Integer> autosmelt = EnchantmentHelper.getEnchantments(head); if (autosmelt.isEmpty()) return; int autosmeltlevel = autosmelt.get(InitEnchants.AUTOSMELT); Block block = event.getState().getBlock(); World world = event.getWorld(); BlockPos pos = event.getPos(); int x = event.getPos().getX(); int y = event.getPos().getY(); int z = event.getPos().getZ(); ItemStack smelt = FurnaceRecipes.instance().getSmeltingResult(new ItemStack(block)); if (autosmeltlevel == 1) { if (smelt.getItem() == Item.getItemFromBlock(Blocks.AIR) && !player.capabilities.isCreativeMode) { world.destroyBlock(pos, true); } if (block != null) { world.setBlockToAir(pos); player.addExperience(1); ItemStack stack = FurnaceRecipes.instance().getSmeltingResult(new ItemStack(block)); stack.setCount(1); EntityItem it = new EntityItem(world, x, y, z, stack); world.spawnEntity(it); } } }
  6. The class is a copy of another of my blocks, and when is in my inventory I can see "testmod:reinforced_glass#inventory" I've registered it correctly and every other block's item model works except this one Edit: I'm an idiot, I forgot it.. Thanks!
  7. Hello, I've created a custom block with connected textures and everything works perfectly except the item in the inventory. I've tried using { "parent": "testmod:block/reinforced_glass_c0" } and the parent is: { "parent": "block/cube_all", "textures": { "all": "testmod:blocks/reinforced_glass/reinforced_glass0C" } } I render my blocks with it (and yeah is the vanilla method) trying to remove the item/reinforced_glass.json minecraft gives an error because the file doesn't exist. How can I fix it? The placed block works perfectly
  8. Then I don't understand the problem... I don't understand what I have to change
  9. But I have to check if the player has this item no?
  10. The code above pass the "if player has the item in the inventory" check, I mean after if (mp.inventory.hasItemStack(pixie)) { I added a System.out.println with random text and it is printed.
  11. Hello, I'm trying to cancel a death event if player has the item in his inventory however the event is not cancelled even if using System.out.println(e.isCancelable() + " < cancellabe | cancelled > " + e.isCanceled()); After "e.setCancelled(true);" gives me true for both I keep dying without have the item removed from the inventory. Here's my DeathEvent: @EventBusSubscriber public class EntityDeath { @SubscribeEvent(priority = EventPriority.HIGHEST) @Mod.EventHandler public void onEntityDeath(LivingDeathEvent e) { World world = e.getEntity().getEntityWorld(); if (world.isRemote) { return; } if (!world.isRemote) { if (e.getEntityLiving() instanceof EntityPlayer) { EntityPlayerMP mp = (EntityPlayerMP) e.getEntity(); ItemStack pixie = new ItemStack(InitItems.PIXIE); FoodStats food = mp.getFoodStats(); if (mp.inventory.hasItemStack(pixie)) { System.out.println(e.isCancelable() + " < cancellabe | cancelled > " + e.isCanceled()); e.setCanceled(true); System.out.println(e.isCancelable() + " < cancellabe | cancelled > " + e.isCanceled()); mp.heal(20F); food.setFoodLevel(20); food.setFoodSaturationLevel(20); world.playSound(mp, mp.getPosition(), SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.BLOCKS, 1, 1); pixie.setCount(pixie.getCount() - 1); } } } } }
  12. Hello, I'm trying to generate some structure when a particular action is performed, I have this class as Structuregenerator public class StructureGenerator { public static final StructureGen CAGE_TRAP = new StructureGen("cage_trap"); public static final StructureGen WISHING_WELL = new StructureGen("wishing_well"); public static final StructureGen AMERICAN_FLAG = new StructureGen("american_flag"); public static void generateStructure(WorldGenerator generator, World world, Random random, int x, int y, int z) { BlockPos pos = new BlockPos(x, y, z); if (world.getWorldType() != WorldType.FLAT) { if (!world.isRemote) { generator.generate(world, random, pos); } } } } And I use: StructureGenerator.generateStructure(StructureGenerator.CAGE_TRAP, worldIn, r, player.getPosition().add(3,0,0).getX(),player.getPosition().add(0,-2,0).getY(),player.getPosition().add(0,0,-1).getZ()); But it keeps to spawn me the last Structure added (AMERICAN_FLAG), why? How to fix this?
  13. LOL. I've solved, was really stupid and thanks for your help, you really helped me. For mods: This thread can be closed
  14. I know but I have it in another class that manage my cooldowns and I cant add "ItemStack stack" to that method, that's why I need to get the itemstack and the item damage
  15. Can you help me to do it? I don't know how to do it
  16. Do you mean: ItemStack stack = new ItemStack(InitItems.REPAIR_GEM, 1, i); if (stack.getMetadata() == 0) { Oh... No no, I was trying to implement a repair gem (an original name lol) into my mod
  17. I have a problem with the code: I was trying to create a repair gem compatible with baubles, the problem is when I try to check the metadata of the item. The item is unlocalized with "repair_gem" and it has 4 different variants (weak, normal, advanced and extreme) which have less cooldown between 2 repair public boolean canRepair() { for (int i = 0; i < RepairGemTypes.values().length; i++) { // weak = 0; // normal = 1; // advanced = 2; // extreme = 3; ItemStack stack = new ItemStack(InitItems.REPAIR_GEM, 1, i); if (stack.getItemDamage() == 0) { if (r.tickCount >= 200) { r.tickCount = 0; r.shouldUpdate = false; return true; } } else if (stack.getItemDamage() == 1) { if (r.tickCount >= 120) { r.tickCount = 0; r.shouldUpdate = false; return true; } } else if (stack.getItemDamage() == 2) { if (r.tickCount >= 60) { r.tickCount = 0; r.shouldUpdate = false; return true; } } else if (stack.getItemDamage() == 3) { if (r.tickCount >= 20) { r.tickCount = 0; r.shouldUpdate = false; return true; } } } return false; } but it always prints the metadata 0 How can I fix this?
  18. Okay changed but I still have the same problem
×
×
  • Create New...

Important Information

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