
AzizD
Members-
Posts
20 -
Joined
-
Last visited
Recent Profile Visitors
784 profile views
AzizD's Achievements

Tree Puncher (2/8)
1
Reputation
-
[1.16.4] Checking an item with a certain enchantment.
AzizD replied to AzizD's topic in Modder Support
Wow that actually worked. Thank you very much! -
I made an event that ignites tnt if held item has fire aspect. I can ignite the tnt but i how can i detect the fire aspect enchantment? I tried using EnchantmentHelper but didn't find anything useful. Here is my code. @SubscribeEvent public static void fireAspectTnt(final PlayerInteractEvent event){ PlayerEntity player = event.getPlayer(); World world = event.getWorld(); BlockPos blockPos = event.getPos(); BlockState block = world.getBlockState(blockPos); Hand hand = event.getHand(); Item item = player.getHeldItem(hand).getItem(); if(!world.isRemote) { if (block.getBlock() instanceof TNTBlock) { if (item instanceof SwordItem) { //Check the sword if it has Fire Aspect. if(true) { block.getBlock().catchFire(block, world, blockPos, null, null); world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), 11); } } } } }
-
You can change config options without running the game. Config folder is in the same directory as mods folder.
-
Maybe copper ore disabled in the config. Try to enable it.
-
I got it.
-
It looks way better. Thanks for the advice. @Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { Set e = ImmutableSet.of( Enchantments.SHARPNESS, Enchantments.LOOTING, Enchantments.FIRE_ASPECT, Enchantments.UNBREAKING, Enchantments.KNOCKBACK ); return e.contains(enchantment); }
-
@Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { Enchantment[] enchantments = { Enchantments.SHARPNESS, Enchantments.LOOTING, Enchantments.FIRE_ASPECT, Enchantments.UNBREAKING, Enchantments.KNOCKBACK, Enchantments.MENDING, }; for(int i=0;i<enchantments.length;i++){ if(enchantments[i] == enchantment){ return true; } } return false; } I wrote this and it worked. Thx.
-
@Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { if(enchantment == Enchantments.SHARPNESS) { enchantment.canApply(stack); } return true; } I changed with this but same error.
-
@Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { enchantment = Enchantments.SHARPNESS; return enchantment.canApply(stack.getItem().getDefaultInstance()); } I tried to override this method. Whenever i put the item in the enchantment table game crashes with java.lang.StackOverflowError.
-
I created a custom item that extends TieredItem. I want it to be enchantable through the enchantment table with Sharpnes, Looting etc. I can enchant but only the unbreaking enchantment shows up.
-
Finally i fixed the all problems. I added this condition and thats all. world.chunkExists(specialItemEntity.chunkCoordX,specialItemEntity.chunkCoordZ) Final code is : EventHandler class package com.azizd.thunderbird.events; import com.azizd.thunderbird.Thunderbird; import com.azizd.thunderbird.entities.SpecialItemEntity; import com.azizd.thunderbird.init.itemInit; import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = Thunderbird.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class EventHandler { public static void register(){} @SubscribeEvent public static void crimsonIngotCraft(EntityJoinWorldEvent event){ Entity entity = event.getEntity(); World world = entity.world; double posX = entity.getPosX(); double posY = entity.getPosY(); double posZ = entity.getPosZ(); SpecialItemEntity specialItemEntity = new SpecialItemEntity(world, posX, posY, posZ); if(entity instanceof ItemEntity && !(entity instanceof SpecialItemEntity)){ ItemEntity itemEntity = (ItemEntity) event.getEntity(); ItemStack item = itemEntity.getItem(); if(item.getItem() == itemInit.RED_PEARL.get()){ if(world.chunkExists(specialItemEntity.chunkCoordX,specialItemEntity.chunkCoordZ)) { event.setCanceled(true); specialItemEntity.setItem(itemEntity.getItem().getStack()); specialItemEntity.setPickupDelay(30); specialItemEntity.setMotion(itemEntity.getMotion()); world.addEntity(specialItemEntity); } } } } } SpecialItemEntity class package com.azizd.thunderbird.entities; import com.azizd.thunderbird.init.itemInit; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class SpecialItemEntity extends ItemEntity { private ItemEntity entity = new ItemEntity(this.world,this.getPosX(),this.getPosY(),this.getPosZ()); public SpecialItemEntity(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } @Override public void tick() { if(this.inWater && !this.world.isRemote){ this.setDead(); int count = this.getItem().getCount(); entity.setPosition(this.getPosX(),this.getPosY(),this.getPosZ()); entity.setItem(new ItemStack(itemInit.CRIMSON_INGOT.get())); entity.getItem().setCount(count); this.world.addEntity(entity); } else{ super.tick(); } } }
-
This is not the issue.
-
But i still have a bug. If specialItemEntity is in the world. I can't join that world.
-
Finally i fixed all the problems. Now it works exactly what i want. This is my EventHandler Method @SubscribeEvent public static void crimsonIngotCraft(EntityJoinWorldEvent event){ Entity entity = event.getEntity(); World world = entity.world; double posX = entity.getPosX(); double posY = entity.getPosY(); double posZ = entity.getPosZ(); if(entity instanceof ItemEntity && !(entity instanceof SpecialItemEntity)){ ItemEntity itemEntity = (ItemEntity) event.getEntity(); if(itemEntity.getItem().getItem() == itemInit.RED_PEARL.get()){ event.setCanceled(true); SpecialItemEntity specialItemEntity = new SpecialItemEntity(world,posX,posY,posZ); specialItemEntity.setItem(itemEntity.getItem().getStack()); specialItemEntity.setPickupDelay(50); specialItemEntity.setMotion(itemEntity.getMotion()); world.addEntity(specialItemEntity); } } } And this is my SpecialItemEntity class package com.azizd.thunderbird.entities; import com.azizd.thunderbird.init.itemInit; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.extensions.IForgeEntity; public class SpecialItemEntity extends ItemEntity implements IForgeEntity { public SpecialItemEntity(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } ItemEntity entity = new ItemEntity(getEntityWorld(),this.getPosX(),this.getPosY(),this.getPosZ()); @Override public void tick() { if(this.inWater){ this.setDead(); int count = this.getItem().getCount(); entity.setPosition(this.getPosX(),this.getPosY(),this.getPosZ()); entity.setItem(new ItemStack(itemInit.CRIMSON_INGOT.get())); entity.getItem().setCount(count); this.world.addEntity(entity); } else{ super.tick(); } } } Thanks for the helps.
-
I solved the pickup bug. The only problem is SpecialItemEntity motion.