Jump to content

ChasePlays

Members
  • Posts

    8
  • Joined

  • Last visited

ChasePlays's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. @warjort Ah, I apologize for being so illiterate today. I understand now thank you!
  2. perhaps I didnt word this correctly, I know how LivingHurtEvent works and how to check if player was damaged by lightning. Thats not what I am trying to achieve. You know how AxeItem has event-like methods such as onLeftClickEntity and onUsingTick? I want to create my own class named AxeItemEx that extends AxeItem so that I may create my own custom event-like methods such as the one listed above (onHurtByLightning). Thing is I have no idea how the event-like methods from AxeItem class work since they are from the interface IForgeItem and there is no proper documentation on either of them and I haven't seen anybody else on this forum trying to achieve what I am trying to do. So long story short I am trying to create an event-like method that can be overriden by any custom item Ex. public class ThunderAxe extends AxeItemEx{ @Override public void onHurtByLightning(Player p, int amnt){ //do whatever I want here when this event is triggered } }
  3. I am trying to create a method that can be overridden in my AxeItemEx class that extends AxeItem Ex. The method in AxeItemEx public void onHurtByLightning(Player p, int amnt){ //Gather Player/or Entity instance and DamageSource instance //and check if the damage came from a lightning bolt //then return the Player/or Entity instance and the amount of damage the player recieived } I want this method to run every tick and check when the player has recieived damage and then check if the damage is caused from a lightning bolt and if it is true it will trigger that method in any Custom Item that extends my custom AxeItemEx class so then you could be able to call it like this @Override public void onHurtByLightning(Player p, int amnt){ p.displayClientMessage(Component.literal("Damage: " + amnt), false); } I have no idea how to make this happen but here are the things I tried to do. 1. Created a new class named AxeHurtEvent and extended Event(I did not understand what I was suppose to do) 2.Created a new class that implemented IForgeItem(probably not what I am looking for) none of the above work for obvious reasons as I have no clue how they work since the code isnt present. Any ideas or explanations? Side Note: I know you cant have a return Object in a void method but I have no clue how the regular Events work and how they are able to store the correct object instances in their constructor so that we may use it for our needs.
  4. I am created a packet that spawns 3 golems and adds a timer to their persistant data along with the name of the owner who spawned them. public boolean handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context context = supplier.get(); context.enqueueWork(()-> { Player p = context.getSender(); if(p.getPersistentData().contains(XprtData.SALUS_CLASS)){ if(!p.getPersistentData().contains(XprtData.SALUS_DEFENDER_TIMER)){ for(int i=0;i<3;i++){ IronGolem golem = (IronGolem) EntityType.IRON_GOLEM.spawn(p.createCommandSourceStack().getLevel(), null, null, p.blockPosition(), MobSpawnType.MOB_SUMMONED, true, false); golem.getPersistentData().putInt(XprtData.SALUS_DEFENDER_TIMER, Utils.Seconds(50)); golem.getPersistentData().putString(XprtData.SALUS_DEFENDER_OWNER, p.getScoreboardName()); golem.setCustomName(Component.literal(ChatFormatting.GOLD + "" + p.getScoreboardName() + "'s Defender")); } p.getPersistentData().putInt(XprtData.SALUS_DEFENDER_TIMER, Utils.Seconds(5)); } else { int time = p.getPersistentData().getInt(XprtData.SALUS_DEFENDER_TIMER); Utils.Message(p, ChatFormatting.RED + "You cannot summon defenders right now, " + Utils.TicksToSeconds(time) + " seconds remaining."); } } }); return true; } the problem is when I call upon their data in an external class here @SubscribeEvent public static void onLivingTick(LivingEvent.LivingTickEvent e){ LivingEntity entity = e.getEntity(); if(entity instanceof IronGolem){ if(entity.getPersistentData().contains(XprtData.SALUS_DEFENDER_TIMER)){ Mob mob = (Mob)entity; for(LivingEntity target : Utils.getNear(entity, 8)){ if(target instanceof Player || target instanceof Villager || target instanceof Wolf || target instanceof IronGolem){ mob.setTarget(null); } else { mob.setTarget(target); } } } if(entity.getPersistentData().contains(XprtData.SALUS_DEFENDER_OWNER)){ String owner = entity.getPersistentData().getString(XprtData.SALUS_DEFENDER_OWNER); for(String pNames : entity.getServer().getPlayerNames()){ if(pNames.equals(owner)){ Player p = entity.getServer().getPlayerList().getPlayerByName(owner); if(entity.distanceTo(p) >= 7f){ entity.teleportTo(p.getBlockX(), p.getBlockY()+1, p.getBlockZ()); } } } } } } neither XprtData.SALUS_DEFENDER_TIMER nor XprtData.SALUS_DEFENDER_OWNER contain any data, for the timer it starts off at 0 when it should be (22*50) and defender owner should contain the players name which instead contains a blank. This isnt my first time doing something like this, ive done it will illagers and it worked perfectly but when it comes to golems it doesnt work at all. I could do with it the timer killing them at -(22*50) but it wont help that i still need the owners name to teleport them to the owner if they move to far away. Any Ideas? Im calling this packet from a keybind by the way EDIT: I figured out the issue I accidentally had the same String name for both of the Strings so it kept overriding eachother
  5. As the title states when I cancel LivingHurtEvent the player takes no damage which is good but it doesn't prevent the screen from shaking and the hurt animation from playing. Is there a way around this?
  6. Can you post the ModEffects class? Or just the custom effect code
  7. Yes there is the method canEnchant(ItemStack item) which returns a boolean but I have no clue how to use it as it crashes when i try to apply the enchantment to an item in the anvil. So its going in the right direction but its causing a crash. Heres the code I used @Override public boolean canEnchant(ItemStack item) { if(item.getItem().equals(Items.DIAMOND_SWORD)){ return false; } return true; }
  8. As the title states, any custom enchantment I create can be applied to any sort of gear even if its not compatible with the enchant. Heres my basic enchantment class public class OverloadEnchantment extends Enchantment { public OverloadEnchantment(EquipmentSlot[] slots) { super(Rarity.RARE, EnchantmentCategory.ARMOR, slots); } @Override public int getMinCost(int p_44679_) { return 15; } @Override public int getMaxCost(int p_44691_) { return 30; } @Override public int getMaxLevel() { return 5; } } it cannot be an enchantment roll in the enchanting table for regular weapons(since its an armor mod) nor can it be applied to these weapons via /enchant command. However if I grab an overload book and apply it to a sword in an anvil, it will apply the enchantment to the sword. This goes for all custom enchantments I create whether or not designed for armor or for weapons/tools.
×
×
  • Create New...

Important Information

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