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

iYM8jXCs3pcvblTE

Members
  • Posts

    26
  • Joined

  • Last visited

Recent Profile Visitors

2085 profile views

iYM8jXCs3pcvblTE's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Yes, although I'm currently studying, I still feel like my current basics are terrible.
  2. When I get the player's entity data, I don't seem to find the 'sethealth' method, and I'm not sure if this is because I'm overlooking him. When I try to look at 'LivingEntity', I find that it is an abstract class and I may not be able to instantiate 'LivingEntity' directly. But currently I hold the entity data provided by the player when he enters the game, I can try to inherit 'LivingEntity' and use the entity data as a parameter to try to modify the target's health.
  3. I thought I could instantiate 'LivingEntity', but I realized later that 'LivingEntity' is an abstract class that I can't instantiate.' LivingEntity' seems to require me to provide an entity's data for 'LivingEntity' to work. Currently I've got the player entity data by listening to the player login. But currently I'm looking for a way to change their properties through this data. The code is as follows main.java package com.AJ.LifeShareing;; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod(Utils.MOD_ID) @Mod.EventBusSubscriber() public class Main { public static Entity [] playerList = new Entity[10]; public static int length = 0; @SubscribeEvent public static void getPlayerList(PlayerEvent.PlayerLoggedInEvent event){ GetPlayerList getPlayerList = new GetPlayerList(); length = GetPlayerList.getPlayerList(event.getEntity(),playerList,length); } @SubscribeEvent public static void setHealth(LivingHurtEvent event){ } } getPlayerList.java package com.AJ.LifeShareing; import net.minecraft.world.entity.Entity; public class GetPlayerList { public static int getPlayerList(Entity player,Entity [] playerList,int length) { for (int i = 0; i == length; i++) { System.out.println("aaaaaaaaaaaaaaaaaaaa" + i); if (player != playerList[i]) { if (i == length) { playerList[i] = player; System.out.println("jjjjjjjjjjjjjj" + playerList[i]); length++; break; } } else { break; } } return length; } }
  4. In 'LivingEntity', regarding the 'entity' parameter, should I fill in the player's entity information?
  5. Hi, The 'LivingEntity' class I tried to instantiate before and then I found out that it is an abstract class. I tried to create a new class to inherit from 'LivingEntity' but I found that it seems that the class I inherit from cannot modify/get data about 'LivingEntity'. It is possible that I am trying the wrong way, I will try again later to create a new class and inherit the class from 'LivingEntity'. I will get back to you with the results.
  6. This code seems to have generated an error when I entered the translation device, please wait while I correct it.
  7. I'm sorry, I just read the following and I may not have expressed myself clearly. I see that 'Attributes.MAX_HEALTH' is the maximum health, can this method/parameter be used to set the current health of a player? If combined with my usage scenario. If a player takes damage (this listener I have implemented to listen to all entities taking damage), then the other players will take the same damage (no change in max health). When a player health reverts (this listener I have implemented to listen for all entities health reverting), then the other players will also revert the same health. Above is the first question: How should I change the current health of other players/self? I get the 'event.getEntity()' injured entity in the event that listens to an entity that is injured, which could also be the entity that caused the injury, I'm still testing that at the moment. Since not all entities need to be injured, I need to execute my code. For example, if I inflict damage on a zombie, I don't need to execute this code. So I added a judgment below the event, but I don't know how to determine an 'Entity' parameter. My current idea is that I listen for events where a player enters the world, and then when a player enters the world, I get that player's entity. Then I put the entity data into an array, and then I determine in the judgment whether the injured entity data is the same as a member of the array. The specific code is as follows for (int i = 0;i < PlayerListArrays.length;i++){ if (event.getEntity() == PlayerListArrays[i]){ } } I know this code may not execute for various reasons, as this is just a rough idea that I have not implemented yet.
  8. Hello, guys. My goal is to change the health of all other players after listening to the health change of one player. I am currently listening to the progress of the entity's health change with the help of all of you. The code is as follows @SubscribeEvent public static void demo04(LivingHurtEvent event){ } In this listener event, I can use 'setAmount' to change the damage caused by this event. I can also use 'getAmount' to get the value of the damage caused by this event. But I've searched the source code of this event/class for a long time, but I still can't find a way to change the health of myself or other players. I only found a way to change health in the 'minecraft' game.(net.minecraft.world.entity.LivingEntity) setHealth public void setHealth(float p_21154_) But when I want to call it, I find that I don't have the parameter needed for this method. The parameter could be the player's parameter or the target entity's parameter. I'm not sure, I'm still double checking this source code. Ultimately, my question is whether there is a more convenient class/event/method for 'forge' to change the player's health. If this idea doesn't fit, are there other ways to achieve the same goal.
  9. Mr. diesieben07 und Mr. Luis_ST. Ich danke Ihnen für Ihre Geduld. Erst jetzt habe ich gelernt, dass "Listen Events" als Parameter zurückgegeben werden, also habe ich auch gelernt, dass man Methoden direkt mit Parametern aufrufen kann. Ich stelle den Ereigniscode zur Verfügung, weil es sich um ein geringfügiges Problem handelt und ich ein sehr schlechter Fragesteller wäre, wenn Sie auch für dieses Problem den Ereigniscode selbst durchgehen müssten. Ich verwende derzeit ein Übersetzungsgerät, um mit Ihnen zu kommunizieren, daher werden viele Wörter nicht klar und deutlich zu verstehen sein, und ich entschuldige mich für etwaige Missverständnisse. Ich bin Ihnen beiden dankbar, dass Sie sich trotz Ihres vollen Terminkalenders die Zeit genommen haben, um meine Fragen zu beantworten. Ich gebe Ihnen beiden ein Dankeschön, um meine Dankbarkeit auszudrücken. Ich danke Ihnen nochmals. :):)
  10. Thanks for the tip, I managed to get the data I wanted in the return parameters of the listened event. Here is part of the code @SubscribeEvent public static void Demo02(LivingHurtEvent event) { System.out.println("sadawedawdawdawdadwa" + '\n' + event.getAmount()); }
  11. It occurred to me. Can I get the data I want by getting the parameters of the event instantiation.
  12. I just checked the description of "LivingHurtEvent" and he tells me that the event does not return results and if I instantiate the event/class and then call his method, I can't get the return value (amount,source). Do I have to get the return value I want in some other way. Here is the code for the "LivingHurtEvent" event /* * Copyright (c) Forge Development LLC and contributors * SPDX-License-Identifier: LGPL-2.1-only */ package net.minecraftforge.event.entity.living; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.LivingEntity; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.Cancelable; /** * LivingHurtEvent is fired when an Entity is set to be hurt. <br> * This event is fired whenever an Entity is hurt in * {@code LivingEntity#actuallyHurt(DamageSource, float)} and * {@code Player#actuallyHurt(DamageSource, float)}.<br> * <br> * This event is fired via the {@link ForgeHooks#onLivingHurt(LivingEntity, DamageSource, float)}.<br> * <br> * {@link #source} contains the DamageSource that caused this Entity to be hurt. <br> * {@link #amount} contains the amount of damage dealt to the Entity that was hurt. <br> * <br> * This event is {@link Cancelable}.<br> * If this event is canceled, the Entity is not hurt.<br> * <br> * This event does not have a result. {@link HasResult}<br> * <br> * This event is fired on the {@link MinecraftForge#EVENT_BUS}. * @see LivingDamageEvent **/ @net.minecraftforge.eventbus.api.Cancelable public class LivingHurtEvent extends LivingEvent { private final DamageSource source; private float amount; public LivingHurtEvent(LivingEntity entity, DamageSource source, float amount) { super(entity); this.source = source; this.amount = amount; } public DamageSource getSource() { return source; } public float getAmount() { return amount; } public void setAmount(float amount) { this.amount = amount; } } I'm wondering if the 'forge' event is only used as a 'forge' listener and not for other purposes. That is, after these events are instantiated, the method is called and cannot provide any return value, or after instantiation, the method is called and cannot change the data, because the events/classes are only used to listen to minecraft/forge.
  13. Can I instantiate an event/class in 'forge' to call one of its methods? Here is the code I used as an example package com.AJ.LifeShareing;; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.LivingEntity; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod(Utils.MOD_ID) @Mod.EventBusSubscriber() public class Main { public static LivingEntity a; public static DamageSource b; public static float c; public static float d; @SubscribeEvent public static void Demo02(LivingHurtEvent event) { LivingHurtEvent livingHurtEvent = new LivingHurtEvent(a,b,c); d = livingHurtEvent.getAmount(); System.out.println("aaaaaaaaaaaaaaaaaaa" + '\n' + d); } }
  14. OK, I have understood what you are trying to say and thank you very much for your patience in answering the almost common sense questions of the rookies.
  15. Yes, I'm sorry, I just realized that the previous "AttackEntityEvent" was a class/event. And "getDamage" is a method. That's why I couldn't listen to this event. I have understood the reason. Native events, meaning events from "minecraft", not "forge" or other third party events. (Ultimately what I want to say is whether "forge" can only call/listen to events from "forge" and not from "minecraft", or whether "minecraft" has no event system) When I checked the "forge" event system in the past two days, I didn't find any events related to listening to player health, is this because if you want to listen to player health, you can only listen to it from events that may cause damage. (For example, when the player falls, I can only insert the action I want to perform into the method that will calculate the fall damage)
×
×
  • Create New...

Important Information

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