Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

AMOnDuck

Members
  • Posts

    10
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

AMOnDuck's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. So I should attach the capability to all itemstacks?
  2. I have a cooldown capability that I want to attach to items with specific enchants and it attaches fine when loading in but when you drop the item or enchant an existing item with the target enchant it won't attach. Here's the relevant code @Mod.EventBusSubscriber(modid = PondWeaponMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public static class Events { @SubscribeEvent public static void attachCapabilityEnchantedItemEvent(AttachCapabilitiesEvent<ItemStack> event) { if(event.getObject() instanceof ItemStack) { if (!event.getObject().getStack().getEnchantmentTagList().isEmpty()){ System.out.println(event.getObject().getStack().getEnchantmentTagList()); if (EnchantmentHelper.getEnchantments(event.getObject().getStack()).get(ModEnchantments.thunder) != null) { event.addCapability(new ResourceLocation(PondWeaponMod.MODID, "cooldown"), new CooldownCapability()); } } } } } Any ideas on how to properly handle this?
  3. After a while of tinkering with it I managed to get it to work by looking at the inventoryscreen code so thanks for the suggestions!
  4. I'm making an item that when held down is supposed to show a copy of the player at the raytraced position for the local client only, any ideas on how to accomplish this? Version 1.16.5
  5. I see, thank you for taking the time to answer such a stupid question then, I haven't had to use lambda expressions much in java so far so this didn't occur to me. Packets seem to be working just fine now
  6. I think I have everything mostly down however this little bit of the packet sending is causing me grief: private static void respawnPlayer(ServerPlayerEntity player) { ImmortalityRespawnToClient msg = new ImmortalityRespawnToClient(true); PondWeaponMod.simpleChannel.send(PacketDistributor.PLAYER.with(player), msg); } I cannot figure out how the PacketDistributor#PLAYER.with function wants me to pass the ServerPlayerEntity. It seems to ask for a Supplier<ServerPlayerEntity> but I cannot cast or figure out how to insert a ServerPlayerEntity into that. If you could help me out here (or at least point me in the right direction) that would be greatly appreciated.
  7. Thanks for the quick response luis, I could indeed find the logic I needed in Deathscreen, if I run into any trouble causing it to activate I may post an update unless I decide that It is more fit for a diffrent topic
  8. I'm trying to make a client respawn when certain conditions are met which I currently accomplish by just setting the player health to 20 however this does not cause the death screen to disapear. Is there a way to eighter make the deathscreen disapear or send a message to the client to emulate a respawn button press? If anyone knows of a better way to handle this that would work aswell.
  9. So far I've managed to implement your first two points which fixed my problem, I guess it was trying to spawn the entity on the client side and then started the cooldown again which caused it to not execute on the server side, the cooldown also takes the correct amount of ticks now. I've still had some trouble implementing a capability so I suppose I will post an update once i manage that, or another post if I don't.
  10. I'm making an enchantment that causes lightning to be spawn at the location the player is looking when the player rightclicks an item its aplied to which seemed to work fine but after implementing the cooldown on it i ran into a problem: lightning is rarely ever spawned however sometimes it seems to work normally. Here is my code, the event is at the bottom: package net.pondsmp.pondweapons.enchantments; import com.google.gson.internal.$Gson$Preconditions; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentType; import net.minecraft.entity.CreatureAttribute; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.LightningBoltEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.INBT; import net.minecraft.server.MinecraftServer; import net.minecraft.util.CooldownTracker; import net.minecraft.util.DamageSource; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.FMLWorldPersistenceHook; import net.minecraftforge.fml.common.Mod; import net.pondsmp.pondweapons.PondWeaponMod; import net.pondsmp.pondweapons.init.ModEnchantments; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.jmx.Server; import org.lwjgl.system.CallbackI; import java.util.ArrayList; import java.util.Map; public class Thunder extends Enchantment { // private final Enchantment.Rarity rarity= Rarity.VERY_RARE; // private final EnchantmentType type = EnchantmentType.WEAPON; // private final EquipmentSlotType slots = EquipmentSlotType.MAINHAND; private final int minlvl = 1; private final int maxlvl = 1; private final boolean treasureEnch = true; private final boolean curse = false; private final boolean tradable = false; private final boolean loot = false; private final boolean book = false; private static CooldownTracker cooldown = new CooldownTracker(); public Thunder(Rarity rarityIn, EnchantmentType typeIn, EquipmentSlotType[] slots) { super(rarityIn, typeIn, slots); setRegistryName("thunder"); } public Thunder(Rarity rarityIn, EnchantmentType typeIn, EquipmentSlotType slots) { super(rarityIn, typeIn, new EquipmentSlotType[]{slots}); setRegistryName("thunder"); } /** * Returns the minimum level that the enchantment can have. */ @Override public int getMinLevel() { return this.minlvl; } /** * Returns the maximum level that the enchantment can have. */ @Override public int getMaxLevel() { return maxlvl; } /** * Calculates the damage protection of the enchantment based on level and damage source passed. */ @Override public int calcModifierDamage(int level, DamageSource source) { return 0; } /** * Calculates the additional damage that will be dealt by an item with this enchantment. This alternative to * calcModifierDamage is sensitive to the targets EnumCreatureAttribute. */ @Override public float calcDamageByCreature(int level, CreatureAttribute creatureType) { return 0.0F; } /** * Called whenever a mob is damaged with an item that has this enchantment on it. */ public void onEntityDamaged(LivingEntity user, Entity target, int level) { } /** * Whenever an entity that has this enchantment on one of its associated items is damaged this method will be called. */ public void onUserHurt(LivingEntity user, Entity attacker, int level) { } @Override public boolean isTreasureEnchantment() { return treasureEnch; } @Override public boolean isCurse() { return curse; } /** * Checks if the enchantment can be sold by villagers in their trades. */ @Override public boolean canVillagerTrade() { return tradable; } /** * Checks if the enchantment can be applied to loot table drops. */ @Override public boolean canGenerateInLoot() { return loot; } /** * This applies specifically to applying at the enchanting table. The other method {@link #canApply(ItemStack)} * applies for <i>all possible</i> enchantments. * @param stack * @return */ public boolean canApplyAtEnchantingTable(ItemStack stack) { return stack.canApplyAtEnchantingTable(this); } /** * Is this enchantment allowed to be enchanted on books via Enchantment Table * @return false to disable the vanilla feature */ public boolean isAllowedOnBooks() { return book; } @Mod.EventBusSubscriber(modid = PondWeaponMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public static class Events{ @SubscribeEvent public static void rightClickEvent(PlayerInteractEvent.RightClickItem event){ Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(event.getPlayer().getHeldItemMainhand()); if (enchantments.get(ModEnchantments.thunder) != null) { if (!cooldown.hasCooldown(event.getPlayer().getHeldItemMainhand().getItem())) { cooldown.setCooldown(event.getPlayer().getHeldItemMainhand().getItem(), 600); ArrayList<String> list = new ArrayList<String>(); RayTraceResult block = event.getPlayer().pick(250, 0, true); if(block.getType() == RayTraceResult.Type.BLOCK) { BlockPos blockpos = ((BlockRayTraceResult) block).getPos(); LightningBoltEntity lightning = EntityType.LIGHTNING_BOLT.create(event.getWorld()); lightning.setLocationAndAngles((double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), (float) 0.0, (float) 0.0); // lightning.setCaster(event.getPlayer()); System.out.println(lightning); event.getWorld().addEntity(lightning); } } else { System.out.println(cooldown.getCooldown(event.getPlayer().getHeldItemMainhand().getItem(), 0.0f)); } } } @SubscribeEvent public static void tickEvent(TickEvent event){ cooldown.tick(); } } } which when rigthclicking a bit gives the following output: [01:44:13] [Server thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.38333333 [01:44:13] [Render thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.26 [01:44:13] [Server thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.26 [01:44:13] [Render thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.13333334 [01:44:13] [Server thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.13333334 [01:44:14] [Render thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.04 [01:44:14] [Server thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.04 [01:44:14] [Render thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:177]: LightningBoltEntity['Lightning Bolt'/837, l='ClientLevel', x=522.00, y=69.00, z=-622.00] [01:44:14] [Server thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.975 [01:44:14] [Render thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.8433333 [01:44:14] [Server thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.8433333 [01:44:15] [Render thread/INFO] [STDOUT/]: [net.pondsmp.pondweapons.enchantments.Thunder$Events:rightClickEvent:182]: 0.6566667 I should probably mention I decided to start modding the day before yesterday so i'm pretty new but I have enough experience with java.
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.