mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Minecraft 1.21.5
Co-authored-by: Ven <[email protected]> Co-authored-by: Jonathing <[email protected]>
This commit is contained in:
548 files changed
+5432
-7867
No files matched your search
@@ -15,9 +15,8 @@ import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.LayeredRegistryAccess;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.server.RegistryLayer;
|
||||
import net.minecraft.util.random.WeightedList;
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
|
||||
@@ -62,7 +61,6 @@ import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.random.WeightedRandomList;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
@@ -293,7 +291,7 @@ public final class ForgeEventFactory {
|
||||
|
||||
/**
|
||||
* Specialized variant of {@link #checkSpawnPosition} for spawners, as they have slightly different checks.
|
||||
* @see #CheckSpawnPosition
|
||||
* @see #checkSpawnPosition(Mob, ServerLevelAccessor, EntitySpawnReason)
|
||||
* @implNote See in-line comments about custom spawn rules.
|
||||
*/
|
||||
public static boolean checkSpawnPositionSpawner(Mob mob, ServerLevelAccessor level, EntitySpawnReason spawnType, SpawnData spawnData, BaseSpawner spawner) {
|
||||
@@ -331,7 +329,7 @@ public final class ForgeEventFactory {
|
||||
* The only code that changes is the {@link Mob#finalizeSpawn} call.
|
||||
* @return The SpawnGroupData from this event, or null if it was canceled. The return value of this method has no bearing on if the entity will be spawned.
|
||||
* @see MobSpawnEvent.FinalizeSpawn
|
||||
* @see Mob#finalizeSpawn(ServerLevelAccessor, DifficultyInstance, MobSpawnType, SpawnGroupData, CompoundTag)
|
||||
* @see Mob#finalizeSpawn(ServerLevelAccessor, DifficultyInstance, EntitySpawnReason, SpawnGroupData)
|
||||
* @apiNote Callers do not need to check if the entity's spawn was cancelled, as the spawn will be blocked by Forge.
|
||||
* @implNote Changes to the signature of this method must be reflected in the method redirector coremod.
|
||||
*/
|
||||
@@ -507,7 +505,7 @@ public final class ForgeEventFactory {
|
||||
boolean isCanceled = post(new EntityMountEvent(entityMounting, entityBeingMounted, entityMounting.level(), isMounting));
|
||||
|
||||
if(isCanceled) {
|
||||
entityMounting.absMoveTo(entityMounting.getX(), entityMounting.getY(), entityMounting.getZ(), entityMounting.yRotO, entityMounting.xRotO);
|
||||
entityMounting.absSnapTo(entityMounting.getX(), entityMounting.getY(), entityMounting.getZ(), entityMounting.yRotO, entityMounting.xRotO);
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
@@ -533,8 +531,8 @@ public final class ForgeEventFactory {
|
||||
post(new PlayerFlyableFallEvent(player, distance, multiplier));
|
||||
}
|
||||
|
||||
public static boolean onPlayerSpawnSet(Player player, ResourceKey<Level> levelKey, BlockPos pos, boolean forced) {
|
||||
return post(new PlayerSetSpawnEvent(player, levelKey, pos, forced));
|
||||
public static boolean onPlayerSpawnSet(ServerPlayer player, ServerPlayer.RespawnConfig config) {
|
||||
return post(new PlayerSetSpawnEvent(player, config));
|
||||
}
|
||||
|
||||
public static PlayerSpawnPhantomsEvent onPlayerSpawnPhantom(Player player, int phantomsToSpawn) {
|
||||
@@ -623,7 +621,7 @@ public final class ForgeEventFactory {
|
||||
|
||||
var canContinueSleep = evt.getResult();
|
||||
if (canContinueSleep == Result.DEFAULT)
|
||||
return !player.level().isDay();
|
||||
return !player.level().isBrightOutside();
|
||||
else
|
||||
return canContinueSleep == Result.ALLOW;
|
||||
}
|
||||
@@ -829,12 +827,12 @@ public final class ForgeEventFactory {
|
||||
post(new TickEvent.ServerTickEvent.Post(haveTime, server));
|
||||
}
|
||||
|
||||
public static WeightedRandomList<MobSpawnSettings.SpawnerData> getPotentialSpawns(LevelAccessor level, MobCategory category, BlockPos pos, WeightedRandomList<MobSpawnSettings.SpawnerData> oldList) {
|
||||
public static WeightedList<MobSpawnSettings.SpawnerData> getPotentialSpawns(LevelAccessor level, MobCategory category, BlockPos pos, WeightedList<MobSpawnSettings.SpawnerData> oldList) {
|
||||
LevelEvent.PotentialSpawns event = new LevelEvent.PotentialSpawns(level, category, pos, oldList);
|
||||
if (post(event))
|
||||
return WeightedRandomList.create();
|
||||
return WeightedList.of();
|
||||
//System.out.println("List: " + oldList.unwrap() + " " + event.getSpawnerDataList());
|
||||
return WeightedRandomList.create(event.getSpawnerDataList());
|
||||
return WeightedList.of(event.getSpawnerDataList());
|
||||
}
|
||||
|
||||
public static void onAdvancementEarned(Player player, AdvancementHolder holder) {
|
||||
@@ -913,8 +911,8 @@ public final class ForgeEventFactory {
|
||||
return fire(new LivingSwapItemsEvent.Hands(entity));
|
||||
}
|
||||
|
||||
public static ShieldBlockEvent onShieldBlock(LivingEntity blocker, DamageSource source, float blocked) {
|
||||
return fire(new ShieldBlockEvent(blocker, source, blocked));
|
||||
public static ShieldBlockEvent onShieldBlock(LivingEntity blocker, DamageSource source, float blocked, ItemStack blockedWith) {
|
||||
return fire(new ShieldBlockEvent(blocker, source, blocked, blockedWith));
|
||||
}
|
||||
|
||||
public static void onEntityEnterSection(Entity entity, long packedOldPos, long packedNewPos) {
|
||||
@@ -925,7 +923,7 @@ public final class ForgeEventFactory {
|
||||
return post(new LivingEvent.LivingTickEvent(entity));
|
||||
}
|
||||
|
||||
public static LivingFallEvent onLivingFall(LivingEntity entity, float distance, float damageMultiplier) {
|
||||
public static LivingFallEvent onLivingFall(LivingEntity entity, double distance, float damageMultiplier) {
|
||||
return fire(new LivingFallEvent(entity, distance, damageMultiplier));
|
||||
}
|
||||
|
||||
@@ -1090,7 +1088,7 @@ public final class ForgeEventFactory {
|
||||
return fire(new LootingLevelEvent(target, cause, level));
|
||||
}
|
||||
|
||||
public static boolean fireFarmlandTrampleEvent(ServerLevel level, BlockPos pos, BlockState state, float fallDistance, Entity entity) {
|
||||
public static boolean fireFarmlandTrampleEvent(ServerLevel level, BlockPos pos, BlockState state, double fallDistance, Entity entity) {
|
||||
return post(new BlockEvent.FarmlandTrampleEvent(level, pos, state, fallDistance, entity));
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.gametest.framework.GameTest;
|
||||
import net.minecraft.gametest.framework.GameTestGenerator;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.gametest.ForgeGameTestHooks;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Game tests are registered on client or server startup.
|
||||
* It is only run once for a given instance of the game if {@link ForgeGameTestHooks#isGametestEnabled} returns true.
|
||||
* This is the preferred way to register your game tests.
|
||||
* <p>
|
||||
* Fired on the Mod bus, see {@link IModBusEvent}.
|
||||
*/
|
||||
public class RegisterGameTestsEvent extends Event implements IModBusEvent {
|
||||
private final Set<Method> gameTestMethods;
|
||||
|
||||
public RegisterGameTestsEvent(Set<Method> gameTestMethods) {
|
||||
this.gameTestMethods = gameTestMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an entire class to the game test registry.
|
||||
* All methods annotated with {@link GameTest} or {@link GameTestGenerator} will be registered.
|
||||
* If the set of enabled batches is non-empty, a method will only be registered if its
|
||||
* {@link GameTest#batch() batch} is listed.
|
||||
*
|
||||
* @param testClass the test class to register to the game test registry
|
||||
*/
|
||||
public void register(Class<?> testClass) {
|
||||
Arrays.stream(testClass.getDeclaredMethods()).forEach(this::register);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a single method to the game test registry.
|
||||
* The method will only be registered if it is annotated with {@link GameTest} or {@link GameTestGenerator}.
|
||||
* If the set of enabled batches is non-empty, the method will only be registered if its
|
||||
* {@link GameTest#batch() batch} is listed.
|
||||
*
|
||||
* @param testMethod the test method to register to the game test registry
|
||||
*/
|
||||
public void register(Method testMethod) {
|
||||
this.gameTestMethods.add(testMethod);
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,9 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
/**
|
||||
* LivingFallEvent is fired when an Entity is set to be falling.<br>
|
||||
* This event is fired whenever an Entity is set to fall in
|
||||
* {@link LivingEntity#causeFallDamage(float, float, DamageSource)}.<br>
|
||||
* {@link LivingEntity#causeFallDamage(double, float, DamageSource)}.<br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeHooks#onLivingFall(LivingEntity, float, float)}.<br>
|
||||
* This event is fired via the {@link net.minecraftforge.event.ForgeEventFactory#onLivingFall(LivingEntity, double, float)}.<br>
|
||||
* <br>
|
||||
* {@link #distance} contains the distance the Entity is to fall. If this event is canceled, this value is set to 0.0F.
|
||||
* <br>
|
||||
@@ -28,19 +28,18 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public class LivingFallEvent extends LivingEvent
|
||||
{
|
||||
private float distance;
|
||||
public class LivingFallEvent extends LivingEvent {
|
||||
private double distance;
|
||||
private float damageMultiplier;
|
||||
public LivingFallEvent(LivingEntity entity, float distance, float damageMultiplier)
|
||||
{
|
||||
|
||||
public LivingFallEvent(LivingEntity entity, double distance, float damageMultiplier) {
|
||||
super(entity);
|
||||
this.setDistance(distance);
|
||||
this.setDamageMultiplier(damageMultiplier);
|
||||
this.distance = distance;
|
||||
this.damageMultiplier = damageMultiplier;
|
||||
}
|
||||
|
||||
public float getDistance() { return distance; }
|
||||
public void setDistance(float distance) { this.distance = distance; }
|
||||
public double getDistance() { return this.distance; }
|
||||
public void setDistance(double distance) { this.distance = distance; }
|
||||
public float getDamageMultiplier() { return damageMultiplier; }
|
||||
public void setDamageMultiplier(float damageMultiplier) { this.damageMultiplier = damageMultiplier; }
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
@@ -18,70 +19,56 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* at least for players.
|
||||
*/
|
||||
@Cancelable
|
||||
public class ShieldBlockEvent extends LivingEvent
|
||||
{
|
||||
public class ShieldBlockEvent extends LivingEvent {
|
||||
private final DamageSource source;
|
||||
private final float originalBlocked;
|
||||
private float dmgBlocked;
|
||||
private boolean shieldTakesDamage = true;
|
||||
private final ItemStack blockedWith;
|
||||
|
||||
public ShieldBlockEvent(LivingEntity blocker, DamageSource source, float blocked)
|
||||
{
|
||||
public ShieldBlockEvent(LivingEntity blocker, DamageSource source, float blocked, ItemStack blockedWith) {
|
||||
super(blocker);
|
||||
this.source = source;
|
||||
this.originalBlocked = blocked;
|
||||
this.dmgBlocked = blocked;
|
||||
this.blockedWith = blockedWith;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The damage source.
|
||||
*/
|
||||
public DamageSource getDamageSource()
|
||||
{
|
||||
/** @return The damage source. */
|
||||
public DamageSource getDamageSource() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The original amount of damage blocked, which is the same as the original
|
||||
* incoming damage value.
|
||||
*/
|
||||
public float getOriginalBlockedDamage()
|
||||
{
|
||||
/** @return The original amount of damage blocked, which is the same as the original incoming damage value. */
|
||||
public float getOriginalBlockedDamage() {
|
||||
return this.originalBlocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current amount of damage blocked, as a result of this event.
|
||||
*/
|
||||
public float getBlockedDamage()
|
||||
{
|
||||
/** @return The current amount of damage blocked, as a result of this event. */
|
||||
public float getBlockedDamage() {
|
||||
return this.dmgBlocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls if {@link LivingEntity#hurtCurrentlyUsedShield} is called.
|
||||
* @return If the shield item will take durability damage or not.
|
||||
*/
|
||||
public boolean shieldTakesDamage()
|
||||
{
|
||||
/** @return If the shield item will take durability damage or not. */
|
||||
public boolean shieldTakesDamage() {
|
||||
return this.shieldTakesDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how much damage is blocked by this action.<br>
|
||||
* Note that initially the blocked amount is the entire attack.<br>
|
||||
* Sets how much damage is blocked by this action.
|
||||
* <p>Note that initially the blocked amount is the entire attack.</p>
|
||||
*/
|
||||
public void setBlockedDamage(float blocked)
|
||||
{
|
||||
public void setBlockedDamage(float blocked) {
|
||||
this.dmgBlocked = Mth.clamp(blocked, 0, this.originalBlocked);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the shield will take durability damage or not.
|
||||
*/
|
||||
public void setShieldTakesDamage(boolean damage)
|
||||
{
|
||||
/** Sets if the shield will take durability damage or not. */
|
||||
public void setShieldTakesDamage(boolean damage) {
|
||||
this.shieldTakesDamage = damage;
|
||||
}
|
||||
|
||||
/** @return The item that was used to block damage. */
|
||||
public ItemStack getBlockedWith() {
|
||||
return this.blockedWith;
|
||||
}
|
||||
}
|
||||
@@ -6,48 +6,67 @@
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This event is fired when a player's spawn point is set or reset.<br>
|
||||
* This event is fired when a player's spawn point is set or reset.
|
||||
* <p>
|
||||
* The event can be canceled, which will prevent the spawn point from being changed.
|
||||
*/
|
||||
@Cancelable
|
||||
public class PlayerSetSpawnEvent extends PlayerEvent
|
||||
{
|
||||
private final ResourceKey<Level> spawnLevel;
|
||||
private final boolean forced;
|
||||
@Nullable
|
||||
private final BlockPos newSpawn;
|
||||
public class PlayerSetSpawnEvent extends PlayerEvent {
|
||||
private final @Nullable ServerPlayer.RespawnConfig config;
|
||||
|
||||
public PlayerSetSpawnEvent(Player player, ResourceKey<Level> spawnLevel, @Nullable BlockPos newSpawn, boolean forced)
|
||||
{
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
private final ResourceKey<Level> spawnLevel;
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
private final boolean forced;
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
private final @Nullable BlockPos newSpawn;
|
||||
|
||||
public PlayerSetSpawnEvent(ServerPlayer player, @Nullable ServerPlayer.RespawnConfig config) {
|
||||
super(player);
|
||||
this.spawnLevel = spawnLevel;
|
||||
this.newSpawn = newSpawn;
|
||||
this.forced = forced;
|
||||
this.config = config;
|
||||
|
||||
boolean hasConfig = config != null;
|
||||
this.forced = hasConfig && config.forced();
|
||||
this.spawnLevel = hasConfig ? config.dimension() : Level.OVERWORLD;
|
||||
this.newSpawn = hasConfig ? config.pos() : null;
|
||||
}
|
||||
|
||||
public boolean isForced()
|
||||
{
|
||||
return forced;
|
||||
/** @return The config for the player respawn */
|
||||
public @Nullable ServerPlayer.RespawnConfig getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
/**
|
||||
* The new spawn position, or null if the spawn position is being reset.
|
||||
* @return If the new spawn point is forced
|
||||
* @deprecated Use {@link ServerPlayer.RespawnConfig#forced()} via {@link #getConfig()}
|
||||
*/
|
||||
@Nullable
|
||||
public BlockPos getNewSpawn()
|
||||
{
|
||||
return newSpawn;
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
public boolean isForced() {
|
||||
return this.forced;
|
||||
}
|
||||
|
||||
public ResourceKey<Level> getSpawnLevel()
|
||||
{
|
||||
return spawnLevel;
|
||||
/**
|
||||
* @return The new spawn position, or {@code null} if the spawn position is being reset
|
||||
* @deprecated Use {@link ServerPlayer.RespawnConfig#pos()} via {@link #getConfig()}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
public @Nullable BlockPos getNewSpawn() {
|
||||
return this.newSpawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The new spawn dimension, defaulting to {@link Level#OVERWORLD} if it is {@code null}
|
||||
* @deprecated Use {@link ServerPlayer.RespawnConfig#dimension()} via {@link #getConfig()}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
public ResourceKey<Level> getSpawnLevel() {
|
||||
return this.spawnLevel;
|
||||
}
|
||||
}
|
||||
@@ -337,9 +337,9 @@ public class BlockEvent extends Event {
|
||||
@Cancelable
|
||||
public static class FarmlandTrampleEvent extends BlockEvent {
|
||||
private final Entity entity;
|
||||
private final float fallDistance;
|
||||
private final double fallDistance;
|
||||
|
||||
public FarmlandTrampleEvent(ServerLevel level, BlockPos pos, BlockState state, float fallDistance, Entity entity) {
|
||||
public FarmlandTrampleEvent(ServerLevel level, BlockPos pos, BlockState state, double fallDistance, Entity entity) {
|
||||
super(level, pos, state);
|
||||
this.entity = entity;
|
||||
this.fallDistance = fallDistance;
|
||||
@@ -349,7 +349,7 @@ public class BlockEvent extends Event {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public float getFallDistance() {
|
||||
public double getFallDistance() {
|
||||
return fallDistance;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,42 +10,44 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.ProgressListener;
|
||||
import net.minecraft.util.random.WeightedRandomList;
|
||||
import net.minecraft.util.random.Weighted;
|
||||
import net.minecraft.util.random.WeightedList;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.storage.ServerLevelData;
|
||||
import net.minecraftforge.common.ForgeInternalHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.UnmodifiableView;
|
||||
|
||||
/**
|
||||
* This event is fired whenever an event involving a {@link LevelAccessor} occurs.
|
||||
* <p>
|
||||
* All children of this event are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}.
|
||||
*/
|
||||
public class LevelEvent extends Event
|
||||
{
|
||||
public class LevelEvent extends Event {
|
||||
private final LevelAccessor level;
|
||||
|
||||
public LevelEvent(LevelAccessor level)
|
||||
{
|
||||
public LevelEvent(LevelAccessor level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level this event is affecting}
|
||||
*/
|
||||
public LevelAccessor getLevel()
|
||||
{
|
||||
public LevelAccessor getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@@ -59,26 +61,23 @@ public class LevelEvent extends Event
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
|
||||
* on both logical sides.
|
||||
**/
|
||||
public static class Load extends LevelEvent
|
||||
{
|
||||
public static class Load extends LevelEvent {
|
||||
public Load(LevelAccessor level) { super(level); }
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired whenever a level unloads.
|
||||
* This event is fired whenever a level unloads in
|
||||
* {@link Minecraft#setLevel(ClientLevel)},
|
||||
* {@link Minecraft#setLevel(ClientLevel, ReceivingLevelScreen.Reason)},
|
||||
* {@link MinecraftServer#stopServer()},
|
||||
* {@link Minecraft#clearLevel(Screen)}, and
|
||||
* {@link ForgeInternalHandler#onDimensionUnload(Unload)}.
|
||||
* {@link Minecraft#clearClientLevel(Screen)}.
|
||||
* <p>
|
||||
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
|
||||
* on both logical sides.
|
||||
**/
|
||||
public static class Unload extends LevelEvent
|
||||
{
|
||||
public static class Unload extends LevelEvent {
|
||||
public Unload(LevelAccessor level) { super(level); }
|
||||
}
|
||||
|
||||
@@ -92,8 +91,7 @@ public class LevelEvent extends Event
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
public static class Save extends LevelEvent
|
||||
{
|
||||
public static class Save extends LevelEvent {
|
||||
public Save(LevelAccessor level) { super(level); }
|
||||
}
|
||||
|
||||
@@ -110,18 +108,15 @@ public class LevelEvent extends Event
|
||||
* @see ServerLevelData#isInitialized()
|
||||
*/
|
||||
@Cancelable
|
||||
public static class CreateSpawnPosition extends LevelEvent
|
||||
{
|
||||
public static class CreateSpawnPosition extends LevelEvent {
|
||||
private final ServerLevelData settings;
|
||||
|
||||
public CreateSpawnPosition(LevelAccessor level, ServerLevelData settings)
|
||||
{
|
||||
public CreateSpawnPosition(LevelAccessor level, ServerLevelData settings) {
|
||||
super(level);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public ServerLevelData getSettings()
|
||||
{
|
||||
public ServerLevelData getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
@@ -131,22 +126,20 @@ public class LevelEvent extends Event
|
||||
*
|
||||
* <p>If an entry is added to the list, it needs to be a globally unique instance.</p>
|
||||
*
|
||||
* The event is called in {@link net.minecraft.world.level.NaturalSpawner#mobsAt(ServerLevel,
|
||||
* StructureManager, ChunkGenerator, MobCategory, RandomSource, BlockPos)}.</p>
|
||||
* The event is called in {@link net.minecraft.world.level.NaturalSpawner#mobsAt(ServerLevel, StructureManager,
|
||||
* ChunkGenerator, MobCategory, BlockPos, Holder)}.</p>
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* Canceling the event will result in an empty list, meaning no entity will be spawned.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class PotentialSpawns extends LevelEvent
|
||||
{
|
||||
public static class PotentialSpawns extends LevelEvent {
|
||||
private final MobCategory mobcategory;
|
||||
private final BlockPos pos;
|
||||
private final List<MobSpawnSettings.SpawnerData> list;
|
||||
private final List<MobSpawnSettings.SpawnerData> view;
|
||||
private final List<Weighted<MobSpawnSettings.SpawnerData>> list;
|
||||
private final @UnmodifiableView List<Weighted<MobSpawnSettings.SpawnerData>> view;
|
||||
|
||||
public PotentialSpawns(LevelAccessor level, MobCategory category, BlockPos pos, WeightedRandomList<MobSpawnSettings.SpawnerData> oldList)
|
||||
{
|
||||
public PotentialSpawns(LevelAccessor level, MobCategory category, BlockPos pos, WeightedList<MobSpawnSettings.SpawnerData> oldList) {
|
||||
super(level);
|
||||
this.pos = pos;
|
||||
this.mobcategory = category;
|
||||
@@ -158,50 +151,39 @@ public class LevelEvent extends Event
|
||||
this.view = Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the category of the mobs in the spawn list.}
|
||||
*/
|
||||
public MobCategory getMobCategory()
|
||||
{
|
||||
return mobcategory;
|
||||
/** @return the category of the mobs in the spawn list. */
|
||||
public MobCategory getMobCategory() {
|
||||
return this.mobcategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the block position where the chosen mob will be spawned.}
|
||||
*/
|
||||
public BlockPos getPos()
|
||||
{
|
||||
return pos;
|
||||
/** @return the block position where the chosen mob will be spawned. */
|
||||
public BlockPos getPos() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the list of mobs that can potentially be spawned.}
|
||||
*/
|
||||
public List<MobSpawnSettings.SpawnerData> getSpawnerDataList()
|
||||
{
|
||||
return view;
|
||||
/** @return the list of mobs that can potentially be spawned. */
|
||||
public @UnmodifiableView List<Weighted<MobSpawnSettings.SpawnerData>> getSpawnerDataList() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a SpawnerData entry to the spawn list.
|
||||
*
|
||||
* @param data SpawnerData entry to be appended to the spawn list.
|
||||
* @param data SpawnerData entry to be appended to the spawn list.
|
||||
* @param weight The weight for the data entry to have in the list.
|
||||
*/
|
||||
public void addSpawnerData(MobSpawnSettings.SpawnerData data)
|
||||
{
|
||||
list.add(data);
|
||||
public void addSpawnerData(MobSpawnSettings.SpawnerData data, int weight) {
|
||||
this.list.add(new Weighted<>(data, weight));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SpawnerData entry from the spawn list.
|
||||
* Removes all entries of the given SpawnerData from the spawn list.
|
||||
*
|
||||
* @param data SpawnerData entry to be removed from the spawn list.
|
||||
*
|
||||
* {@return {@code true} if the spawn list contained the specified element.}
|
||||
* @return {@code true} if the spawn list contained the specified element.
|
||||
*/
|
||||
public boolean removeSpawnerData(MobSpawnSettings.SpawnerData data)
|
||||
{
|
||||
return list.remove(data);
|
||||
public boolean removeSpawnerData(MobSpawnSettings.SpawnerData data) {
|
||||
return this.list.removeIf(weighted -> weighted.value().equals(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.event.village;
|
||||
import java.util.List;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.entity.npc.VillagerData;
|
||||
import net.minecraft.world.entity.npc.VillagerProfession;
|
||||
import net.minecraft.world.entity.npc.VillagerTrades.ItemListing;
|
||||
@@ -16,35 +17,29 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.event.server.ServerAboutToStartEvent;
|
||||
|
||||
/**
|
||||
* VillagerTradesEvent is fired during the {@link ServerAboutToStartEvent}. It is used to gather the trade lists for each profession.
|
||||
* It is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
* It is fired once for each registered villager profession.
|
||||
* Villagers pick two trades from their trade map, based on their level.
|
||||
* Villager level is increased by successful trades.
|
||||
* The map is populated for levels 1-5 (inclusive), so Map#get will never return null for those keys.
|
||||
* Levels outside of this range do nothing, as specified by {@link VillagerData#canLevelUp(int)} which is called before attempting to level up.
|
||||
* To add trades to the merchant, simply add new trades to the list. {@link BasicItemListing} provides a default implementation.
|
||||
* VillagerTradesEvent is fired during the {@link ServerAboutToStartEvent}. It is used to gather the trade lists for each profession.
|
||||
* <p>It is fired on the {@link MinecraftForge#EVENT_BUS}.</p>
|
||||
* <p>It is fired once for each registered villager profession.</p>
|
||||
* <p>Villagers pick two trades from their trade map, based on their level.</p>
|
||||
* <p>Villager level is increased by successful trades.</p>
|
||||
* <p>The map is populated for levels 1-5 (inclusive), so getting a value will never return null for those keys.</p>
|
||||
* <p>Levels outside of this range do nothing, as specified by {@link VillagerData#canLevelUp(int)} which is called before attempting to level up.</p>
|
||||
* <p>To add trades to the merchant, simply add new trades to the list.</p>
|
||||
*/
|
||||
public class VillagerTradesEvent extends Event
|
||||
{
|
||||
|
||||
public class VillagerTradesEvent extends Event {
|
||||
protected Int2ObjectMap<List<ItemListing>> trades;
|
||||
protected VillagerProfession type;
|
||||
protected ResourceKey<VillagerProfession> type;
|
||||
|
||||
public VillagerTradesEvent(Int2ObjectMap<List<ItemListing>> trades, VillagerProfession type)
|
||||
{
|
||||
public VillagerTradesEvent(Int2ObjectMap<List<ItemListing>> trades, ResourceKey<VillagerProfession> type) {
|
||||
this.trades = trades;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Int2ObjectMap<List<ItemListing>> getTrades()
|
||||
{
|
||||
return trades;
|
||||
public Int2ObjectMap<List<ItemListing>> getTrades() {
|
||||
return this.trades;
|
||||
}
|
||||
|
||||
public VillagerProfession getType()
|
||||
{
|
||||
return type;
|
||||
public ResourceKey<VillagerProfession> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,13 @@
|
||||
|
||||
package net.minecraftforge.event.village;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.world.entity.npc.VillagerTrades.ItemListing;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
@@ -15,28 +20,39 @@ import net.minecraftforge.event.server.ServerAboutToStartEvent;
|
||||
/**
|
||||
* WandererTradesEvent is fired during the {@link ServerAboutToStartEvent}. It is used to gather the trade lists for the wandering merchant.
|
||||
* It is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
* The wandering merchant picks a few trades from {@code generic} and a single trade from {@code rare}.
|
||||
* The wandering merchant picks {@link Pool#rolls} from each {@link Pool}
|
||||
* To add trades to the merchant, simply add new trades to the list. {@link BasicItemListing} provides a default implementation.
|
||||
*/
|
||||
public class WandererTradesEvent extends Event
|
||||
{
|
||||
public class WandererTradesEvent extends Event {
|
||||
protected List<Pool> pools;
|
||||
|
||||
protected List<ItemListing> generic;
|
||||
protected List<ItemListing> rare;
|
||||
|
||||
public WandererTradesEvent(List<ItemListing> generic, List<ItemListing> rare)
|
||||
{
|
||||
this.generic = generic;
|
||||
this.rare = rare;
|
||||
public WandererTradesEvent(List<Pair<ItemListing[], Integer>> pools) {
|
||||
this.pools = pools.stream().map(Pool::new).collect(Util.toMutableList());
|
||||
}
|
||||
|
||||
public List<ItemListing> getGenericTrades()
|
||||
{
|
||||
return generic;
|
||||
public List<Pool> getPools() {
|
||||
return pools;
|
||||
}
|
||||
|
||||
public List<ItemListing> getRareTrades()
|
||||
{
|
||||
return rare;
|
||||
public static class Pool {
|
||||
private int rolls;
|
||||
private List<ItemListing> entries;
|
||||
|
||||
public Pool(Pair<ItemListing[], Integer> data) {
|
||||
this.rolls = data.getRight();
|
||||
this.entries = new ArrayList<>(Arrays.asList(data.getLeft()));
|
||||
}
|
||||
|
||||
public int getRolls() {
|
||||
return this.rolls;
|
||||
}
|
||||
|
||||
public void setRolls(int value) {
|
||||
this.rolls = value;
|
||||
}
|
||||
|
||||
public List<ItemListing> getEntries() {
|
||||
return this.entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user