Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

LeeCrafts

Members
  • Joined

  • Last visited

Everything posted by LeeCrafts

  1. --------------------------------------- CLEANER, MORE EFFICIENT IMPLEMENTATION FOR ALL LIVING ENTITIES, NOT JUST PLAYERS: https://forums.minecraftforge.net/topic/111159-version-1182-solved-custom-status-effect-that-changes-the-players-or-any-entitys-size-part-ii/ (If you just want to increase the hitbox size) https://forums.minecraftforge.net/topic/111362-version-1182-solved-increased-hitbox-size-only-works-for-entity-collision-but-not-for-block-collision/ --------------------------------------- Solved. Turns out that I should not be using EntityEvent.Size. Instead, I have to use the AABB class and call setBoundingBox(). Here is the code in a nutshell if any of you were wondering: public class BigEffect extends MobEffect { public BigEffect(MobEffectCategory mobEffectCategory, int color) { super(mobEffectCategory, color); } @Override public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) { // (This if-statement makes it not work) // if (!pLivingEntity.level.isClientSide()) { pLivingEntity.setBoundingBox(new AABB(pLivingEntity.getX()+2.5, pLivingEntity.getY()+3.6, pLivingEntity.getZ()+2.5, pLivingEntity.getX()-2.5, pLivingEntity.getY(), pLivingEntity.getZ()-2.5)); // } super.applyEffectTick(pLivingEntity, pAmplifier); } @Override public boolean isDurationEffectTick(int pDuration, int pAmplifier) { return true; } } As you can see, no capabilities are needed. And there is no need to check if the player does NOT have the custom status effect because setBoundingBox() is temporary for only 1 tick (or so it seems). As mentioned in the comment in my code above, it does not work if I make sure that the entity is not in the client side. I guess that's just the nature of AABBs. (Side note, but I just don't know how to use setNewSize() from EntityEvent.Size. I don't really need it anymore, but what kinda confuses me is that I see other people using it and that it works for them. Not a big deal though.)
  2. Hello, I am having a little trouble implementing an efficient method of changing the player's size whenever that player gains a certain custom status effect. The player's size would revert back to normal when the effect ends. This is the class for my custom status effect that makes the player bigger (currently I am focusing on the player's hitbox size rather than its rendered size): public class BigEffect extends MobEffect { public BigEffect(MobEffectCategory mobEffectCategory, int color) { super(mobEffectCategory, color); } @Override public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) { if (!pLivingEntity.level.isClientSide() && pLivingEntity instanceof Player player) { // forcibly trigger an EntityEvent.Size event player.setForcedPose(Pose.CROUCHING); } super.applyEffectTick(pLivingEntity, pAmplifier); } @Override public boolean isDurationEffectTick(int pDuration, int pAmplifier) { return true; } } This is the event handler that takes in a EntityEvent.Size event: @SubscribeEvent public static void big(EntityEvent.Size event) { if (!event.getEntity().level.isClientSide() && event.getEntity() instanceof Player player) { if (player.getActiveEffectsMap() != null && player.hasEffect(ModEffects.BIG.get())) { event.setNewSize(new EntityDimensions(5.0F, 3.6F, false), true); } else { event.setNewSize(new EntityDimensions(0.6F, 1.8F, false), true); } } } It technically works, but I have a feeling that my current method is too crude, and I don't want that. Plus, the player's size does not go back to normal when the potion effect wears off (I even tried crouching or swimming to trigger the EntityEvent.Size event, but to no avail). Even when the hitbox is enlarged, the rendered bounding box (which shows when I press F3 + B) does not get bigger. Oh, and another thing, when the player touches a block with its enlarged hitbox, it starts shaking and becomes unable to jump unless it moves away. Are EntityEvent.Size events the only way to resize the player's hitbox? Is it even the right thing to use? Should I still use capabilities, despite the fact that I can easily check a player's potion effects with hasEffect()/getEffect()?
  3. I...barely even know what I just did. I ran ./gradlew -q javaToolchains saw the paths to all my JDKs. Then I navigated through those paths (you have to do it via Terminal) and manually deleted the JDKs I didn't need. Java: 17.0.2, JVM: 17.0.2+8-86 (Oracle Corporation), Arch: x86_64 + Options | Auto-detection: Enabled | Auto-download: Enabled + OpenJDK 17.0.2+8-86 | Location: /Users/wlee2019/Library/Java/JavaVirtualMachines/openjdk-17.0.2/Contents/Home | Language Version: 17 | Vendor: Oracle | Architecture: x86_64 | Is JDK: true | Detected by: Current JVM + Oracle JDK 17.0.2+8-LTS-86 | Location: /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home | Language Version: 17 | Vendor: Oracle | Architecture: x86_64 | Is JDK: true | Detected by: macOS java_home + Oracle JRE 1.8.0_321-b07 | Location: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home | Language Version: 8 | Vendor: Oracle | Architecture: x86_64 | Is JDK: false | Detected by: macOS java_home This is the output I currently have, but it had a lot more unnecessary stuff. I guess the gradlew build ran on the wrong "Current JVM."
  4. I have been suddenly getting this error without even changing the build.gradle or META-INF/mods.toml files. What does it mean by that? Aren't we supposed to use Java 17 for our 1.18.2 mods? I use IntelliJ, and I invalidated caches restarted, but it didn't work. I also made sure my JVM and JDK were both version 17. Was there something I needed to update? This is the output when I run ./gradlew --warning-mode=all build > Configure project : Java: 17.0.2, JVM: 17.0.2+8-LTS-86 (Oracle Corporation), Arch: x86_64 Resolution of the configuration :runtimeClasspathCopy was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. Resolution of the configuration :minecraftCopy was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. Resolution of the configuration :runtimeClasspathCopy2 was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. Resolution of the configuration :minecraftCopy2 was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. Resolution of the configuration :runtimeClasspathCopy3 was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. Resolution of the configuration :minecraftCopy3 was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. Resolution of the configuration :runtimeClasspathCopy4 was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. Resolution of the configuration :minecraftCopy4 was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See https://docs.gradle.org/7.4/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors for more details. > Task :compileJava FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'. > error: release version 17 not supported * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 4s 1 actionable task: 1 executed
  5. I just made a working solution with capabilities and it was one hell of a learning experience. There were many tutorials I had to follow because they were mostly from earlier versions. Below is an example code for anyone else who wants to add ambient noises to silent mobs--and learn how to use custom capabilities. I attach a custom capability (TimeCounter) to iron golems, making each store their own time counter. The counter gets incremented every tick, and once it reaches a certain limit, the iron golem plays a sound and the counter is reset. // must have an interface public interface ITimeCounter { void incrementCounter(); void resetCounter(); void rollLimit(); } // ...and a class implementing the interface public class TimeCounter implements ITimeCounter { public int counter; // current tick counter public int limit; // number of ticks counter must reach for the sound to be played public TimeCounter() { counter = 0; rollLimit(); } @Override public void incrementCounter() { this.counter++; if (counter < 0) resetCounter(); } @Override public void resetCounter() { this.counter = 0; } @Override public void rollLimit() { // adds randomness to limit Random random = new Random(); this.limit = random.nextInt(100) + 100; } } // provides the capability public class TimeCounterProvider implements ICapabilitySerializable<CompoundTag> { private final TimeCounter timeCounter = new TimeCounter(); private final LazyOptional<ITimeCounter> timeCounterLazyOptional = LazyOptional.of(() -> timeCounter); @NotNull @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { return timeCounterLazyOptional.cast(); } // exclude serializeNBT() and deserializeNBT() if you don't need to persist the data // (in that case, also replace ICapabilitySerializable interface with ICapabilityProvider) @Override public CompoundTag serializeNBT() { if (ModCapabilities.TIME_COUNTER_CAPABILITY == null) { return new CompoundTag(); } CompoundTag nbt = new CompoundTag(); nbt.putInt("counter", timeCounter.counter); nbt.putInt("limit", timeCounter.limit); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { if (ModCapabilities.TIME_COUNTER_CAPABILITY != null) { timeCounter.counter = nbt.getInt("counter"); timeCounter.limit = nbt.getInt("limit"); } } // invalidates capability public void invalidate() { timeCounterLazyOptional.invalidate(); } } public class ModCapabilities { // instance of the capability public static Capability<ITimeCounter> TIME_COUNTER_CAPABILITY = CapabilityManager.get(new CapabilityToken<>(){}); // can put other capabilities here } @Mod.EventBusSubscriber(modid = MyMod.MOD_ID) public class ModEvents { // registers the capability @SubscribeEvent public void registerCapabilities(RegisterCapabilitiesEvent event) { event.register(ITimeCounter.class); } // attaches the capability to iron golems @SubscribeEvent public static void onAttachCapabilitiesEvent(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof IronGolem && !event.getObject().getCommandSenderWorld().isClientSide) { TimeCounterProvider timeCounterProvider = new TimeCounterProvider(); event.addCapability(new ResourceLocation(MyMod.MOD_ID, "time_cap"), timeCounterProvider); event.addListener(timeCounterProvider::invalidate); } } // entities get updated every tick @SubscribeEvent public static void ironGolemSound(LivingEvent.LivingUpdateEvent event) { Entity entity = event.getEntity(); if (entity instanceof IronGolem && !entity.level.isClientSide()) { entity.getCapability(ModCapabilities.TIME_COUNTER_CAPABILITY).ifPresent(iTimeCounter -> { TimeCounter timeCounter = (TimeCounter) iTimeCounter; timeCounter.incrementCounter(); // when the counter reaches the limit, sound is played if (timeCounter.counter >= timeCounter.limit) { entity.playSound(ModSounds.IRON_GOLEM_GRUNT.get(), 1.0F, 1.0F); // entity.level.playSound(null, entity.getX(), entity.getY(), entity.getZ(), ModSounds.IRON_GOLEM_GRUNT.get(), SoundSource.AMBIENT, 1.0F, 1.0F); timeCounter.resetCounter(); timeCounter.rollLimit(); } }); } } } Sources I mainly used: https://www.planetminecraft.com/blog/forge-tutorial-capability-system/ https://mcforge.readthedocs.io/en/1.18.x/datastorage/capabilities/ https://forums.minecraftforge.net/topic/106325-1171-forge-capability-how-to-save/
  6. Update: Don't use this solution. See my bottom comment for a solution involving capabilities. My solution works, but for those who are asking the same questions, this is a bit more complex than we wish it to be. If you want to add ambient noises to iron golems for example, you would first need to store each iron golem's relevant data in a list. The relevant data includes its UUID string and tick counter (an int value initialized at 0). I recommend using an extra class for this! Now you must make two event handlers. One handles EntityJoinWorldEvent events, and it checks if event.getEntity() is an iron golem. If so, then add its data to the list. The other event handler handles LivingUpdateEvent events, which--as @diesieben07 mentioned--fires every tick (entities get updated every tick). Get the UUID of the entity being updated (event.getEntity().getStringUUID()), and search through the list to get the matching entity data, aka. the list entry containing the same UUID. Increment that entry's tick counter, and if it reaches an x amount of ticks, then play the noise and reset the counter. Side note: Your LivingUpdateEvent handler probably should check if the entity (iron golem) has died, and if it has, then remove its respective entry from the list. I hope my solution is not unnecessarily complicated. Edit: maybe hash maps are more efficient than lists, but I’ll have to check and come back later.
  7. Hello, I am wondering how I would add ambient sounds to "silent" mobs (such as iron golems, snow golems, and players). I was looking at this forum and I have some questions... Suppose I want to add ambient noises to iron golems. Do I have to use an event handler that takes in a TickEvent.ServerTickEvent argument? And In order to get all iron golems to be able to emit noises, how would I get a list of all registered iron golems?
  8. player.level.playSound(null, player.getX(), player.getY(), player.getZ(), ModSounds.CUSTOM_NOISE.get(), SoundSource.PLAYERS, 1.0F, 1.0F); It works now, thanks. Didn't know I actually had to pass in a null player!
  9. I am a beginner modder with some basic Java knowledge. I have learned how to handle an event in which any entity, including the player, takes damage (e.g. LivingDamageEvent). I am trying to make the mob play a server-side sound whenever it takes damage, and it has worked for any mob except the player. public static void pain(LivingDamageEvent event) { Entity entity = event.getEntityLiving(); if (!entity.level.isClientSide()) { // other effects besides playing sounds if (entity instanceof Player) { Player player = (Player) entity; System.out.println("player hurt"); // this statement prints out // does not play player.playSound(ModSounds.CUSTOM_NOISE.get(), 1.0F, 1.0F); } // plays for any non-player mob else entity.playSound(ModSounds.CUSTOM_NOISE.get(), 1.0F, 1.0F); } } I have tried to follow the docs correctly, but I think I am missing something. Am I even supposed to cast the entity into the Player class? And if Player.playSound's server behavior is "playing the sound to everyone nearby except this player," does that mean I am not supposed to hear it? https://mcforge.readthedocs.io/en/1.18.x/gameeffects/sounds/ Edit: fixed, look at my most recent comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.