mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
1.21.3 update
This commit is contained in:
806 files changed
+6314
-10501
No files matched your search
@@ -8,7 +8,6 @@ package net.minecraftforge.event;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -80,9 +79,9 @@ public class AddReloadListenerEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> reload(final PreparationBarrier stage, final ResourceManager resourceManager, final ProfilerFiller preparationsProfiler, final ProfilerFiller reloadProfiler, final Executor backgroundExecutor, final Executor gameExecutor) {
|
||||
public CompletableFuture<Void> reload(final PreparationBarrier stage, final ResourceManager resourceManager, final Executor backgroundExecutor, final Executor gameExecutor) {
|
||||
if (ModLoader.isLoadingStateValid())
|
||||
return wrapped.reload(stage, resourceManager, preparationsProfiler, reloadProfiler, backgroundExecutor, gameExecutor);
|
||||
return wrapped.reload(stage, resourceManager, backgroundExecutor, gameExecutor);
|
||||
else
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@ import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
|
||||
import net.minecraftforge.client.event.ToastAddEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
@@ -30,6 +33,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.client.gui.components.toasts.Toast;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
@@ -63,22 +67,9 @@ import net.minecraft.world.Difficulty;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.AgeableMob;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.ExperienceOrb;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.MobSpawnType;
|
||||
import net.minecraft.world.entity.SlotAccess;
|
||||
import net.minecraft.world.entity.SpawnGroupData;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.monster.Zombie;
|
||||
@@ -257,8 +248,8 @@ public final class ForgeEventFactory {
|
||||
return post(event);
|
||||
}
|
||||
|
||||
public static NeighborNotifyEvent onNeighborNotify(Level level, BlockPos pos, BlockState state, EnumSet<Direction> notifiedSides, boolean forceRedstoneUpdate) {
|
||||
return fire(new NeighborNotifyEvent(level, pos, state, notifiedSides, forceRedstoneUpdate));
|
||||
public static boolean onNeighborNotify(Level level, BlockPos pos, BlockState state, EnumSet<Direction> notifiedSides, boolean forceRedstoneUpdate) {
|
||||
return post(new NeighborNotifyEvent(level, pos, state, notifiedSides, forceRedstoneUpdate));
|
||||
}
|
||||
|
||||
public static boolean doPlayerHarvestCheck(Player player, BlockState state, boolean success) {
|
||||
@@ -278,7 +269,7 @@ public final class ForgeEventFactory {
|
||||
post(new PlayerDestroyItemEvent(player, stack, slot));
|
||||
}
|
||||
|
||||
public static boolean checkSpawnPlacements(EntityType<?> entityType, ServerLevelAccessor level, MobSpawnType spawnType, BlockPos pos, RandomSource random, boolean defaultResult) {
|
||||
public static boolean checkSpawnPlacements(EntityType<?> entityType, ServerLevelAccessor level, EntitySpawnReason spawnType, BlockPos pos, RandomSource random, boolean defaultResult) {
|
||||
var result = fire(new SpawnPlacementCheck(entityType, level, spawnType, pos, random, defaultResult)).getResult();
|
||||
return result == Result.DEFAULT ? defaultResult : result == Result.ALLOW;
|
||||
}
|
||||
@@ -292,7 +283,7 @@ public final class ForgeEventFactory {
|
||||
* @return True, if the position is valid, as determined by the contract of {@link PositionCheck}.
|
||||
* @see PositionCheck
|
||||
*/
|
||||
public static boolean checkSpawnPosition(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType) {
|
||||
public static boolean checkSpawnPosition(Mob mob, ServerLevelAccessor level, EntitySpawnReason spawnType) {
|
||||
var result = fire(new PositionCheck(mob, level, spawnType, null)).getResult();
|
||||
if (result == Result.DEFAULT)
|
||||
return mob.checkSpawnRules(level, spawnType) && mob.checkSpawnObstruction(level);
|
||||
@@ -304,7 +295,7 @@ public final class ForgeEventFactory {
|
||||
* @see #CheckSpawnPosition
|
||||
* @implNote See in-line comments about custom spawn rules.
|
||||
*/
|
||||
public static boolean checkSpawnPositionSpawner(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData, BaseSpawner spawner) {
|
||||
public static boolean checkSpawnPositionSpawner(Mob mob, ServerLevelAccessor level, EntitySpawnReason spawnType, SpawnData spawnData, BaseSpawner spawner) {
|
||||
var result = fire(new PositionCheck(mob, level, spawnType, null)).getResult();
|
||||
if (result == Result.DEFAULT) {
|
||||
// Spawners do not evaluate Mob#checkSpawnRules if any custom rules are present. This is despite the fact that these two methods do not check the same things.
|
||||
@@ -345,12 +336,12 @@ public final class ForgeEventFactory {
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("deprecation") // Call to deprecated Mob#finalizeSpawn is expected.
|
||||
public static SpawnGroupData onFinalizeSpawn(Mob mob, ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType spawnType, @Nullable SpawnGroupData spawnData) {
|
||||
public static SpawnGroupData onFinalizeSpawn(Mob mob, ServerLevelAccessor level, DifficultyInstance difficulty, EntitySpawnReason spawnType, @Nullable SpawnGroupData spawnData) {
|
||||
var event = new MobSpawnEvent.FinalizeSpawn(mob, level, mob.getX(), mob.getY(), mob.getZ(), difficulty, spawnType, spawnData, null, null);
|
||||
boolean cancel = post(event);
|
||||
|
||||
if (!cancel)
|
||||
return mob.finalizeSpawn(level, event.getDifficulty(), event.getSpawnType(), event.getSpawnData());
|
||||
return mob.finalizeSpawn(level, event.getDifficulty(), event.getSpawnReason(), event.getSpawnData());
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -363,7 +354,7 @@ public final class ForgeEventFactory {
|
||||
*/
|
||||
@Nullable
|
||||
public static MobSpawnEvent.FinalizeSpawn onFinalizeSpawnSpawner(Mob mob, ServerLevelAccessor level, DifficultyInstance difficulty, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag spawnTag, BaseSpawner spawner) {
|
||||
return fire(new MobSpawnEvent.FinalizeSpawn(mob, level, mob.getX(), mob.getY(), mob.getZ(), difficulty, MobSpawnType.SPAWNER, spawnData, spawnTag, spawner));
|
||||
return fire(new MobSpawnEvent.FinalizeSpawn(mob, level, mob.getX(), mob.getY(), mob.getZ(), difficulty, EntitySpawnReason.SPAWNER, spawnData, spawnTag, spawner));
|
||||
}
|
||||
|
||||
public static Result canEntityDespawn(Mob entity, ServerLevelAccessor level) {
|
||||
@@ -469,23 +460,23 @@ public final class ForgeEventFactory {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static InteractionResultHolder<ItemStack> onBucketUse(@NotNull Player player, @NotNull Level level, @NotNull ItemStack stack, @Nullable HitResult target) {
|
||||
public static InteractionResult onBucketUse(@NotNull Player player, @NotNull Level level, @NotNull ItemStack stack, @Nullable HitResult target) {
|
||||
var event = new FillBucketEvent(player, stack, level, target);
|
||||
if (post(event))
|
||||
return new InteractionResultHolder<ItemStack>(InteractionResult.FAIL, stack);
|
||||
return InteractionResult.FAIL;
|
||||
|
||||
if (event.getResult() == Result.ALLOW) {
|
||||
if (player.getAbilities().instabuild)
|
||||
return new InteractionResultHolder<ItemStack>(InteractionResult.SUCCESS, stack);
|
||||
return InteractionResult.SUCCESS.heldItemTransformedTo(stack);
|
||||
|
||||
stack.shrink(1);
|
||||
if (stack.isEmpty())
|
||||
return new InteractionResultHolder<ItemStack>(InteractionResult.SUCCESS, event.getFilledBucket());
|
||||
return InteractionResult.SUCCESS.heldItemTransformedTo(event.getFilledBucket());
|
||||
|
||||
if (!player.getInventory().add(event.getFilledBucket()))
|
||||
player.drop(event.getFilledBucket(), false);
|
||||
|
||||
return new InteractionResultHolder<ItemStack>(InteractionResult.SUCCESS, stack);
|
||||
return InteractionResult.SUCCESS.heldItemTransformedTo(stack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -557,8 +548,8 @@ public final class ForgeEventFactory {
|
||||
return post(new ExplosionEvent.Start(level, explosion));
|
||||
}
|
||||
|
||||
public static void onExplosionDetonate(Level level, Explosion explosion, List<Entity> list, double diameter) {
|
||||
post(new ExplosionEvent.Detonate(level, explosion, list));
|
||||
public static void onExplosionDetonate(Level level, Explosion explosion, List<BlockPos> blocks, List<Entity> entities, double diameter) {
|
||||
post(new ExplosionEvent.Detonate(level, explosion, blocks, entities));
|
||||
}
|
||||
|
||||
public static boolean onCreateWorldSpawn(Level level, ServerLevelData settings) {
|
||||
@@ -636,10 +627,10 @@ public final class ForgeEventFactory {
|
||||
return canContinueSleep == Result.ALLOW;
|
||||
}
|
||||
|
||||
public static InteractionResultHolder<ItemStack> onArrowNock(ItemStack item, Level level, Player player, InteractionHand hand, boolean hasAmmo) {
|
||||
public static InteractionResult onArrowNock(ItemStack item, Level level, Player player, InteractionHand hand, boolean hasAmmo) {
|
||||
var event = new ArrowNockEvent(player, item, hand, level, hasAmmo);
|
||||
if (post(event))
|
||||
return new InteractionResultHolder<ItemStack>(InteractionResult.FAIL, item);
|
||||
return InteractionResult.FAIL;
|
||||
return event.getAction();
|
||||
}
|
||||
|
||||
@@ -681,7 +672,7 @@ public final class ForgeEventFactory {
|
||||
return !post(new LivingDestroyBlockEvent(entity, pos, state));
|
||||
}
|
||||
|
||||
public static boolean getMobGriefingEvent(Level level, @Nullable Entity entity) {
|
||||
public static boolean getMobGriefingEvent(ServerLevel level, @Nullable Entity entity) {
|
||||
if (entity == null)
|
||||
return level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING);
|
||||
|
||||
@@ -887,11 +878,11 @@ public final class ForgeEventFactory {
|
||||
post(new LevelEvent.Save(level));
|
||||
}
|
||||
|
||||
public static void onChunkDataSave(ChunkAccess chunk, LevelAccessor world, CompoundTag data) {
|
||||
public static void onChunkDataSave(ChunkAccess chunk, LevelAccessor world, SerializableChunkData data) {
|
||||
post(new ChunkDataEvent.Save(chunk, world, data));
|
||||
}
|
||||
|
||||
public static void onChunkDataLoad(ChunkAccess chunk, CompoundTag data, ChunkType status) {
|
||||
public static void onChunkDataLoad(ChunkAccess chunk, SerializableChunkData data, ChunkType status) {
|
||||
post(new ChunkDataEvent.Load(chunk, data, status));
|
||||
}
|
||||
|
||||
@@ -1091,4 +1082,8 @@ public final class ForgeEventFactory {
|
||||
public static LootingLevelEvent fireLootingLevel(LivingEntity target, @Nullable DamageSource cause, int level) {
|
||||
return fire(new LootingLevelEvent(target, cause, level));
|
||||
}
|
||||
|
||||
public static boolean fireFarmlandTrampleEvent(ServerLevel level, BlockPos pos, BlockState state, float fallDistance, Entity entity) {
|
||||
return post(new BlockEvent.FarmlandTrampleEvent(level, pos, state, fallDistance, entity));
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This event is fired when the attributes for an ItemStack are being calculated.
|
||||
* Attributes are calculated on the server when equipping and unequipping an item to add and remove attributes respectively, both must be consistent.
|
||||
* Attributes are calculated on the client when rendering an item's tooltip to show relevant attributes.
|
||||
* <br>
|
||||
* Note that this event is fired regardless of if the stack has NBT overriding attributes or not. If your attribute should be
|
||||
* ignored when attributes are overridden, you can check for the presence of the {@code AttributeModifiers} tag.
|
||||
* <br>
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.
|
||||
* /
|
||||
public class ItemAttributeModifierEvent extends Event
|
||||
{
|
||||
private final ItemStack stack;
|
||||
private final EquipmentSlot slotType;
|
||||
private final Multimap<Attribute, AttributeModifier> originalModifiers;
|
||||
private Multimap<Attribute, AttributeModifier> unmodifiableModifiers;
|
||||
@Nullable
|
||||
private Multimap<Attribute, AttributeModifier> modifiableModifiers;
|
||||
|
||||
public ItemAttributeModifierEvent(ItemStack stack, EquipmentSlot slotType, Multimap<Attribute, AttributeModifier> modifiers)
|
||||
{
|
||||
this.stack = stack;
|
||||
this.slotType = slotType;
|
||||
this.unmodifiableModifiers = this.originalModifiers = modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable view of the attribute multimap. Use other methods from this event to modify the attributes map.
|
||||
* Note that adding attributes based on existing attributes may lead to inconsistent results between the tooltip (client)
|
||||
* and the actual attributes (server) if the listener order is different. Using {@link #getOriginalModifiers()} instead will give more consistent results.
|
||||
* /
|
||||
public Multimap<Attribute, AttributeModifier> getModifiers()
|
||||
{
|
||||
return this.unmodifiableModifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute map before any changes from other event listeners was made.
|
||||
* /
|
||||
public Multimap<Attribute, AttributeModifier> getOriginalModifiers()
|
||||
{
|
||||
return this.originalModifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a modifiable map instance, creating it if the current map is currently unmodifiable
|
||||
* /
|
||||
private Multimap<Attribute, AttributeModifier> getModifiableMap()
|
||||
{
|
||||
if (this.modifiableModifiers == null)
|
||||
{
|
||||
this.modifiableModifiers = HashMultimap.create(this.originalModifiers);
|
||||
this.unmodifiableModifiers = Multimaps.unmodifiableMultimap(this.modifiableModifiers);
|
||||
}
|
||||
return this.modifiableModifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new attribute modifier to the given stack.
|
||||
* Modifier must have a consistent UUID for consistency between equipping and unequipping items.
|
||||
* Modifier name should clearly identify the mod that added the modifier.
|
||||
* @param attribute Attribute
|
||||
* @param modifier Modifier instance.
|
||||
* @return True if the attribute was added, false if it was already present
|
||||
* /
|
||||
public boolean addModifier(Attribute attribute, AttributeModifier modifier)
|
||||
{
|
||||
return getModifiableMap().put(attribute, modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a single modifier for the given attribute
|
||||
* @param attribute Attribute
|
||||
* @param modifier Modifier instance
|
||||
* @return True if an attribute was removed, false if no change
|
||||
* /
|
||||
public boolean removeModifier(Attribute attribute, AttributeModifier modifier)
|
||||
{
|
||||
return getModifiableMap().remove(attribute, modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all modifiers for the given attribute
|
||||
* @param attribute Attribute
|
||||
* @return Collection of removed modifiers
|
||||
* /
|
||||
public Collection<AttributeModifier> removeAttribute(Attribute attribute)
|
||||
{
|
||||
return getModifiableMap().removeAll(attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all modifiers for all attributes
|
||||
* /
|
||||
public void clearModifiers()
|
||||
{
|
||||
getModifiableMap().clear();
|
||||
}
|
||||
|
||||
/** Gets the slot containing this stack * /
|
||||
public EquipmentSlot getSlotType()
|
||||
{
|
||||
return this.slotType;
|
||||
}
|
||||
|
||||
/** Gets the item stack instance * /
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.stack;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -21,17 +21,14 @@ import net.minecraftforge.fml.event.IModBusEvent;
|
||||
* <br>
|
||||
* Fired on the Mod bus {@link IModBusEvent}.<br>
|
||||
**/
|
||||
public class EntityAttributeCreationEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public class EntityAttributeCreationEvent extends Event implements IModBusEvent {
|
||||
private final Map<EntityType<? extends LivingEntity>, AttributeSupplier> map;
|
||||
|
||||
public EntityAttributeCreationEvent(Map<EntityType<? extends LivingEntity>, AttributeSupplier> map)
|
||||
{
|
||||
public EntityAttributeCreationEvent(Map<EntityType<? extends LivingEntity>, AttributeSupplier> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public void put(EntityType<? extends LivingEntity> entity, AttributeSupplier map)
|
||||
{
|
||||
public void put(EntityType<? extends LivingEntity> entity, AttributeSupplier map) {
|
||||
if (DefaultAttributes.hasSupplier(entity))
|
||||
throw new IllegalStateException("Duplicate DefaultAttributes entry: " + entity);
|
||||
this.map.put(entity, map);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.*;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -13,12 +14,6 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.MobSpawnType;
|
||||
import net.minecraft.world.entity.SpawnGroupData;
|
||||
import net.minecraft.world.entity.SpawnPlacements;
|
||||
import net.minecraft.world.level.BaseSpawner;
|
||||
import net.minecraft.world.level.ServerLevelAccessor;
|
||||
import net.minecraftforge.common.ForgeInternalHandler;
|
||||
@@ -41,16 +36,14 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
* <p>
|
||||
* {@link AllowDespawn} is not related to the mob spawn event flow, as it fires when a despawn is attempted.
|
||||
*/
|
||||
public abstract class MobSpawnEvent extends EntityEvent
|
||||
{
|
||||
public abstract class MobSpawnEvent extends EntityEvent {
|
||||
private final ServerLevelAccessor level;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected MobSpawnEvent(Mob mob, ServerLevelAccessor level, double x, double y, double z)
|
||||
{
|
||||
protected MobSpawnEvent(Mob mob, ServerLevelAccessor level, double x, double y, double z) {
|
||||
super(mob);
|
||||
this.level = level;
|
||||
this.x = x;
|
||||
@@ -59,40 +52,35 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mob getEntity()
|
||||
{
|
||||
return (Mob) super.getEntity();
|
||||
public Mob getEntity() {
|
||||
return (Mob)super.getEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The level relating to the mob spawn action
|
||||
*/
|
||||
public ServerLevelAccessor getLevel()
|
||||
{
|
||||
public ServerLevelAccessor getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The x-coordinate relating to the mob spawn action
|
||||
*/
|
||||
public double getX()
|
||||
{
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The y-coordinate relating to the mob spawn action
|
||||
*/
|
||||
public double getY()
|
||||
{
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The z-coordinate relating to the mob spawn action
|
||||
*/
|
||||
public double getZ()
|
||||
{
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
@@ -116,11 +104,10 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @see SpawnPlacementRegisterEvent
|
||||
*/
|
||||
@HasResult
|
||||
public static class SpawnPlacementCheck extends Event
|
||||
{
|
||||
public static class SpawnPlacementCheck extends Event {
|
||||
private final EntityType<?> entityType;
|
||||
private final ServerLevelAccessor level;
|
||||
private final MobSpawnType spawnType;
|
||||
private final EntitySpawnReason spawnReason;
|
||||
private final BlockPos pos;
|
||||
private final RandomSource random;
|
||||
private final boolean defaultResult;
|
||||
@@ -130,11 +117,10 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @see {@link SpawnPlacements#checkSpawnRules} for the single call site of this event.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public SpawnPlacementCheck(EntityType<?> entityType, ServerLevelAccessor level, MobSpawnType spawnType, BlockPos pos, RandomSource random, boolean defaultResult)
|
||||
{
|
||||
public SpawnPlacementCheck(EntityType<?> entityType, ServerLevelAccessor level, EntitySpawnReason spawnReason, BlockPos pos, RandomSource random, boolean defaultResult) {
|
||||
this.entityType = entityType;
|
||||
this.level = level;
|
||||
this.spawnType = spawnType;
|
||||
this.spawnReason = spawnReason;
|
||||
this.pos = pos;
|
||||
this.random = random;
|
||||
this.defaultResult = defaultResult;
|
||||
@@ -143,34 +129,30 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
/**
|
||||
* @return The type of entity that checks are being performed for.
|
||||
*/
|
||||
public EntityType<?> getEntityType()
|
||||
{
|
||||
public EntityType<?> getEntityType() {
|
||||
return this.entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The level relating to the mob spawn action
|
||||
*/
|
||||
public ServerLevelAccessor getLevel()
|
||||
{
|
||||
public ServerLevelAccessor getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the type of mob spawn that is happening.
|
||||
* @return The mob spawn type.
|
||||
* @see MobSpawnType
|
||||
* @see EntitySpawnReason
|
||||
*/
|
||||
public MobSpawnType getSpawnType()
|
||||
{
|
||||
return this.spawnType;
|
||||
public EntitySpawnReason getSpawnReason() {
|
||||
return this.spawnReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The position where checks are being evaluated.
|
||||
*/
|
||||
public BlockPos getPos()
|
||||
{
|
||||
public BlockPos getPos() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
@@ -178,8 +160,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* In all vanilla cases, this is equal to {@link ServerLevelAccessor#getRandom()}.
|
||||
* @return The random source being used.
|
||||
*/
|
||||
public RandomSource getRandom()
|
||||
{
|
||||
public RandomSource getRandom() {
|
||||
return this.random;
|
||||
}
|
||||
|
||||
@@ -187,8 +168,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* The default vanilla result is useful if an additional check wants to force {@link Result#ALLOW} only if the vanilla check would succeed.
|
||||
* @return The result of the vanilla spawn placement check.
|
||||
*/
|
||||
public boolean getDefaultResult()
|
||||
{
|
||||
public boolean getDefaultResult() {
|
||||
return this.defaultResult;
|
||||
}
|
||||
}
|
||||
@@ -221,38 +201,34 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @see {@link SpawnPlacementCheck} To modify the result of spawn placements at runtime.
|
||||
*/
|
||||
@HasResult
|
||||
public static class PositionCheck extends MobSpawnEvent
|
||||
{
|
||||
public static class PositionCheck extends MobSpawnEvent {
|
||||
@Nullable
|
||||
private final BaseSpawner spawner;
|
||||
private final MobSpawnType spawnType;
|
||||
private final EntitySpawnReason spawnReason;
|
||||
|
||||
public PositionCheck(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, @Nullable BaseSpawner spawner)
|
||||
{
|
||||
public PositionCheck(Mob mob, ServerLevelAccessor level, EntitySpawnReason spawnReason, @Nullable BaseSpawner spawner) {
|
||||
super(mob, level, mob.getX(), mob.getY(), mob.getZ());
|
||||
this.spawnType = spawnType;
|
||||
this.spawnReason = spawnReason;
|
||||
this.spawner = spawner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the underlying {@link BaseSpawner} instance if this mob was created by a Mob Spawner of some form.
|
||||
* This is always null unless {@link #getSpawnType()} is {@link MobSpawnType#SPAWNER}, and may still be null even then.
|
||||
* This is always null unless {@link #getSpawnReason()} is {@link EntitySpawnReason#SPAWNER}, and may still be null even then.
|
||||
* @return The BaseSpawner responsible for triggering the spawn, or null if none is available.
|
||||
*/
|
||||
@Nullable
|
||||
public BaseSpawner getSpawner()
|
||||
{
|
||||
public BaseSpawner getSpawner() {
|
||||
return spawner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the type of mob spawn that is happening.
|
||||
* @return The mob spawn type.
|
||||
* @see MobSpawnType
|
||||
* @see EntitySpawnReason
|
||||
*/
|
||||
public MobSpawnType getSpawnType()
|
||||
{
|
||||
return this.spawnType;
|
||||
public EntitySpawnReason getSpawnReason() {
|
||||
return this.spawnReason;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,9 +245,8 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @apiNote Callers do not need to check if the entity's spawn was cancelled, as the spawn will be blocked by Forge.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class FinalizeSpawn extends MobSpawnEvent
|
||||
{
|
||||
private final MobSpawnType spawnType;
|
||||
public static class FinalizeSpawn extends MobSpawnEvent {
|
||||
private final EntitySpawnReason spawnReason;
|
||||
@Nullable
|
||||
private final BaseSpawner spawner;
|
||||
|
||||
@@ -285,11 +260,10 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @apiNote Do not construct directly. Access via {@link ForgeEventFactory#onFinalizeSpawn} / {@link ForgeEventFactory#onFinalizeSpawnSpawner}.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public FinalizeSpawn(Mob entity, ServerLevelAccessor level, double x, double y, double z, DifficultyInstance difficulty, MobSpawnType spawnType, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag spawnTag, @Nullable BaseSpawner spawner)
|
||||
{
|
||||
public FinalizeSpawn(Mob entity, ServerLevelAccessor level, double x, double y, double z, DifficultyInstance difficulty, EntitySpawnReason spawnReason, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag spawnTag, @Nullable BaseSpawner spawner) {
|
||||
super(entity, level, x, y, z);
|
||||
this.difficulty = difficulty;
|
||||
this.spawnType = spawnType;
|
||||
this.spawnReason = spawnReason;
|
||||
this.spawnData = spawnData;
|
||||
this.spawnTag = spawnTag;
|
||||
this.spawner = spawner;
|
||||
@@ -299,8 +273,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* Retrieves the {@link DifficultyInstance} for the chunk where the mob is about to be spawned.
|
||||
* @return The local difficulty instance
|
||||
*/
|
||||
public DifficultyInstance getDifficulty()
|
||||
{
|
||||
public DifficultyInstance getDifficulty() {
|
||||
return this.difficulty;
|
||||
}
|
||||
|
||||
@@ -309,19 +282,17 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* The difficulty instance controls how likely certain random effects are to occur, or if certain mob abilities are enabled.
|
||||
* @param inst The new difficulty instance.
|
||||
*/
|
||||
public void setDifficulty(DifficultyInstance inst)
|
||||
{
|
||||
public void setDifficulty(DifficultyInstance inst) {
|
||||
this.difficulty = inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the type of mob spawn that happened (the event that caused the spawn). The enum names are self-explanatory.
|
||||
* @return The mob spawn type.
|
||||
* @see MobSpawnType
|
||||
* @see EntitySpawnReason
|
||||
*/
|
||||
public MobSpawnType getSpawnType()
|
||||
{
|
||||
return this.spawnType;
|
||||
public EntitySpawnReason getSpawnReason() {
|
||||
return this.spawnReason;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,8 +301,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @return The spawn group data.
|
||||
*/
|
||||
@Nullable
|
||||
public SpawnGroupData getSpawnData()
|
||||
{
|
||||
public SpawnGroupData getSpawnData() {
|
||||
return this.spawnData;
|
||||
}
|
||||
|
||||
@@ -340,8 +310,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @param data The new spawn data
|
||||
* @see FinalizeSpawn#getSpawnData
|
||||
*/
|
||||
public void setSpawnData(@Nullable SpawnGroupData data)
|
||||
{
|
||||
public void setSpawnData(@Nullable SpawnGroupData data) {
|
||||
this.spawnData = data;
|
||||
}
|
||||
|
||||
@@ -351,8 +320,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @return The spawn data this entity was or will be loaded from, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public CompoundTag getSpawnTag()
|
||||
{
|
||||
public CompoundTag getSpawnTag() {
|
||||
return this.spawnTag;
|
||||
}
|
||||
|
||||
@@ -361,19 +329,17 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* The only vanilla mob known to use this tag for anything in finalize is tropical fish for setting the variant when spawned via bucket.
|
||||
* @param tag The new spawn tag
|
||||
*/
|
||||
public void setSpawnTag(@Nullable CompoundTag tag)
|
||||
{
|
||||
public void setSpawnTag(@Nullable CompoundTag tag) {
|
||||
this.spawnTag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the underlying {@link BaseSpawner} instance if this mob was created by a Mob Spawner of some form.
|
||||
* This is always null unless {@link #getSpawnType()} is {@link MobSpawnType#SPAWNER}, and may still be null even then.
|
||||
* This is always null unless {@link #getSpawnReason()} is {@link EntitySpawnReason#SPAWNER}, and may still be null even then.
|
||||
* @return The BaseSpawner responsible for triggering the spawn, or null if none is available.
|
||||
*/
|
||||
@Nullable
|
||||
public BaseSpawner getSpawner()
|
||||
{
|
||||
public BaseSpawner getSpawner() {
|
||||
return spawner;
|
||||
}
|
||||
|
||||
@@ -384,8 +350,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* Usually that has no side effects, but callers should be aware.
|
||||
* @param cancel If the spawn should be cancelled (or not).
|
||||
*/
|
||||
public void setSpawnCancelled(boolean cancel)
|
||||
{
|
||||
public void setSpawnCancelled(boolean cancel) {
|
||||
this.getEntity().setSpawnCancelled(cancel);
|
||||
}
|
||||
|
||||
@@ -394,8 +359,7 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
* @return If this mob's spawn is cancelled or not.
|
||||
* @implNote This is enforced in {@link ForgeInternalHandler#builtinMobSpawnBlocker} and a patch in {@link WorldGenRegion#addEntity}
|
||||
*/
|
||||
public boolean isSpawnCancelled()
|
||||
{
|
||||
public boolean isSpawnCancelled() {
|
||||
return this.getEntity().isSpawnCancelled();
|
||||
}
|
||||
}
|
||||
@@ -419,12 +383,9 @@ public abstract class MobSpawnEvent extends EntityEvent
|
||||
// TODO: 1.20 Move to standalone class, as it is unrelated to the complex mob spawning flow.
|
||||
// Such a refactor will allow the BaseSpawner and MobSpawnType params to be hoisted to MobSpawnEvent.
|
||||
@HasResult
|
||||
public static class AllowDespawn extends MobSpawnEvent
|
||||
{
|
||||
public AllowDespawn(Mob mob, ServerLevelAccessor level)
|
||||
{
|
||||
public static class AllowDespawn extends MobSpawnEvent {
|
||||
public AllowDespawn(Mob mob, ServerLevelAccessor level) {
|
||||
super(mob, level, mob.getX(), mob.getY(), mob.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+9
-13
@@ -5,42 +5,38 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.monster.EnderMan;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.extensions.IForgeItem;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
* This event is fired on the forge bus before an Enderman detects that a player is looking at them.
|
||||
* This event is fired on the forge bus before an Monster detects that a player is looking at them.
|
||||
* It will not be fired if the detection is already prevented by {@link IForgeItem#isEnderMask}
|
||||
* <p>
|
||||
* This event is {@link Cancelable}.
|
||||
* If this event is canceled, the Enderman will not target the player.
|
||||
* If this event is canceled, the Monster will not target the player.
|
||||
* <p>
|
||||
* This event does not have a {@link Result}.
|
||||
*/
|
||||
@Cancelable
|
||||
public class EnderManAngerEvent extends LivingEvent
|
||||
{
|
||||
public class MonsterDisguiseEvent extends LivingEvent {
|
||||
private final Player player;
|
||||
|
||||
public EnderManAngerEvent(EnderMan enderman, Player player)
|
||||
{
|
||||
super(enderman);
|
||||
public MonsterDisguiseEvent(Monster monster, Player player) {
|
||||
super(monster);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player that is being checked.
|
||||
*/
|
||||
public Player getPlayer()
|
||||
{
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnderMan getEntity()
|
||||
{
|
||||
return (EnderMan) super.getEntity();
|
||||
public Monster getEntity() {
|
||||
return (Monster)super.getEntity();
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ package net.minecraftforge.event.entity.player;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BowItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -21,16 +21,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public class ArrowNockEvent extends PlayerEvent
|
||||
{
|
||||
public class ArrowNockEvent extends PlayerEvent {
|
||||
private final ItemStack bow;
|
||||
private final InteractionHand hand;
|
||||
private final Level level;
|
||||
private final boolean hasAmmo;
|
||||
private InteractionResultHolder<ItemStack> action;
|
||||
private InteractionResult action;
|
||||
|
||||
public ArrowNockEvent(Player player, @NotNull ItemStack item, InteractionHand hand, Level level, boolean hasAmmo)
|
||||
{
|
||||
public ArrowNockEvent(Player player, @NotNull ItemStack item, InteractionHand hand, Level level, boolean hasAmmo) {
|
||||
super(player);
|
||||
this.bow = item;
|
||||
this.hand = hand;
|
||||
@@ -43,13 +41,11 @@ public class ArrowNockEvent extends PlayerEvent
|
||||
public Level getLevel() { return this.level; }
|
||||
public InteractionHand getHand() { return this.hand; }
|
||||
public boolean hasAmmo() { return this.hasAmmo; }
|
||||
public InteractionResultHolder<ItemStack> getAction()
|
||||
{
|
||||
public InteractionResult getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public void setAction(InteractionResultHolder<ItemStack> action)
|
||||
{
|
||||
public void setAction(InteractionResult action) {
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.block.BaseFireBlock;
|
||||
@@ -338,7 +339,7 @@ public class BlockEvent extends Event {
|
||||
private final Entity entity;
|
||||
private final float fallDistance;
|
||||
|
||||
public FarmlandTrampleEvent(Level level, BlockPos pos, BlockState state, float fallDistance, Entity entity) {
|
||||
public FarmlandTrampleEvent(ServerLevel level, BlockPos pos, BlockState state, float fallDistance, Entity entity) {
|
||||
super(level, pos, state);
|
||||
this.entity = entity;
|
||||
this.fallDistance = fallDistance;
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
|
||||
package net.minecraftforge.event.level;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiManager;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.chunk.status.ChunkType;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
|
||||
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
@@ -27,26 +26,26 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class ChunkDataEvent extends ChunkEvent {
|
||||
private final CompoundTag data;
|
||||
private final SerializableChunkData data;
|
||||
|
||||
public ChunkDataEvent(ChunkAccess chunk, CompoundTag data) {
|
||||
public ChunkDataEvent(ChunkAccess chunk, SerializableChunkData data) {
|
||||
super(chunk);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ChunkDataEvent(ChunkAccess chunk, LevelAccessor world, CompoundTag data) {
|
||||
public ChunkDataEvent(ChunkAccess chunk, LevelAccessor world, SerializableChunkData data) {
|
||||
super(chunk, world);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public CompoundTag getData() {
|
||||
public SerializableChunkData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* ChunkDataEvent.Load is fired when vanilla Minecraft attempts to load Chunk data.<br>
|
||||
* This event is fired during chunk loading in
|
||||
* {@link ChunkSerializer#read(ServerLevel, PoiManager, ChunkPos, CompoundTag)} which means it is async, so be careful.<br>
|
||||
* {@link ChunkSerializer#read(ServerLevel, PoiManager, ChunkPos, SerializableChunkData)} which means it is async, so be careful.<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
@@ -57,7 +56,7 @@ public class ChunkDataEvent extends ChunkEvent {
|
||||
public static class Load extends ChunkDataEvent {
|
||||
private ChunkType status;
|
||||
|
||||
public Load(ChunkAccess chunk, CompoundTag data, ChunkType status) {
|
||||
public Load(ChunkAccess chunk, SerializableChunkData data, ChunkType status) {
|
||||
super(chunk, data);
|
||||
this.status = status;
|
||||
}
|
||||
@@ -79,7 +78,7 @@ public class ChunkDataEvent extends ChunkEvent {
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class Save extends ChunkDataEvent {
|
||||
public Save(ChunkAccess chunk, LevelAccessor world, CompoundTag data) {
|
||||
public Save(ChunkAccess chunk, LevelAccessor world, SerializableChunkData data) {
|
||||
super(chunk, world, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,24 +25,20 @@ import net.minecraft.world.level.Level;
|
||||
* Children do not use {@link HasResult}.<br>
|
||||
* Children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
*/
|
||||
public class ExplosionEvent extends Event
|
||||
{
|
||||
public class ExplosionEvent extends Event {
|
||||
private final Level level;
|
||||
private final Explosion explosion;
|
||||
|
||||
public ExplosionEvent(Level level, Explosion explosion)
|
||||
{
|
||||
public ExplosionEvent(Level level, Explosion explosion) {
|
||||
this.level = level;
|
||||
this.explosion = explosion;
|
||||
}
|
||||
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public Explosion getExplosion()
|
||||
{
|
||||
public Explosion getExplosion() {
|
||||
return explosion;
|
||||
}
|
||||
|
||||
@@ -53,10 +49,8 @@ public class ExplosionEvent extends Event
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Start extends ExplosionEvent
|
||||
{
|
||||
public Start(Level level, Explosion explosion)
|
||||
{
|
||||
public static class Start extends ExplosionEvent {
|
||||
public Start(Level level, Explosion explosion) {
|
||||
super(level, explosion);
|
||||
}
|
||||
}
|
||||
@@ -67,25 +61,23 @@ public class ExplosionEvent extends Event
|
||||
* This event does not use {@link HasResult}.<br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
*/
|
||||
public static class Detonate extends ExplosionEvent
|
||||
{
|
||||
public static class Detonate extends ExplosionEvent {
|
||||
private final List<BlockPos> blocks;
|
||||
private final List<Entity> entityList;
|
||||
|
||||
public Detonate(Level level, Explosion explosion, List<Entity> entityList)
|
||||
{
|
||||
public Detonate(Level level, Explosion explosion, List<BlockPos> blocks, List<Entity> entityList) {
|
||||
super(level, explosion);
|
||||
this.blocks = blocks;
|
||||
this.entityList = entityList;
|
||||
}
|
||||
|
||||
/** return the list of blocks affected by the explosion. */
|
||||
public List<BlockPos> getAffectedBlocks()
|
||||
{
|
||||
return getExplosion().getToBlow();
|
||||
public List<BlockPos> getAffectedBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** return the list of entities affected by the explosion. */
|
||||
public List<Entity> getAffectedEntities()
|
||||
{
|
||||
public List<Entity> getAffectedEntities() {
|
||||
return entityList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,15 +30,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
// TODO: Rename to BlockFeatureGrowEvent in 1.20
|
||||
@HasResult
|
||||
public class SaplingGrowTreeEvent extends LevelEvent
|
||||
{
|
||||
@Deprecated(forRemoval = true, since = "1.21.1") // Dont remove, rename
|
||||
public class SaplingGrowTreeEvent extends LevelEvent {
|
||||
private final RandomSource randomSource;
|
||||
private final BlockPos pos;
|
||||
@Nullable
|
||||
private Holder<ConfiguredFeature<?, ?>> feature;
|
||||
|
||||
public SaplingGrowTreeEvent(LevelAccessor level, RandomSource randomSource, BlockPos pos, @Nullable Holder<ConfiguredFeature<?, ?>> feature)
|
||||
{
|
||||
public SaplingGrowTreeEvent(LevelAccessor level, RandomSource randomSource, BlockPos pos, @Nullable Holder<ConfiguredFeature<?, ?>> feature) {
|
||||
super(level);
|
||||
this.randomSource = randomSource;
|
||||
this.pos = pos;
|
||||
@@ -48,16 +47,14 @@ public class SaplingGrowTreeEvent extends LevelEvent
|
||||
/**
|
||||
* {@return the random source which initiated the sapling growth}
|
||||
*/
|
||||
public RandomSource getRandomSource()
|
||||
{
|
||||
public RandomSource getRandomSource() {
|
||||
return this.randomSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the coordinates of the sapling attempting to grow}
|
||||
*/
|
||||
public BlockPos getPos()
|
||||
{
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -65,24 +62,21 @@ public class SaplingGrowTreeEvent extends LevelEvent
|
||||
* {@return the holder of the feature which will be placed, possibly null}
|
||||
*/
|
||||
@Nullable
|
||||
public Holder<ConfiguredFeature<?, ?>> getFeature()
|
||||
{
|
||||
public Holder<ConfiguredFeature<?, ?>> getFeature() {
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param feature a {@linkplain Holder} referencing a tree feature to be placed instead of the current feature.
|
||||
*/
|
||||
public void setFeature(@Nullable Holder<ConfiguredFeature<?, ?>> feature)
|
||||
{
|
||||
public void setFeature(@Nullable Holder<ConfiguredFeature<?, ?>> feature) {
|
||||
this.feature = feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param featureKey a {@linkplain ResourceKey} referencing a tree feature to be placed instead of the current feature.
|
||||
*/
|
||||
public void setFeature(ResourceKey<ConfiguredFeature<?, ?>> featureKey)
|
||||
{
|
||||
this.feature = this.getLevel().registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(featureKey).orElse(null);
|
||||
public void setFeature(ResourceKey<ConfiguredFeature<?, ?>> featureKey) {
|
||||
this.feature = this.getLevel().registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(featureKey).orElse(null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user