mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 23:13:15 +00:00
1.20.6 Initial Update
New Decompiler Runtime Official mappings ItemStacks arnt Capability providers anymore, use Vanilla's system. Co-authored-by: RealMangoRage <[email protected]> Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
1114 files changed
+24245
-28536
No files matched your search
@@ -21,19 +21,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
* if the output is empty, and the event is not canceled, vanilla behavior will execute. <br>
|
||||
*/
|
||||
@Cancelable
|
||||
public class AnvilUpdateEvent extends Event
|
||||
{
|
||||
|
||||
public class AnvilUpdateEvent extends Event {
|
||||
private final ItemStack left;
|
||||
private final ItemStack right;
|
||||
private final String name;
|
||||
private ItemStack output;
|
||||
private int cost;
|
||||
private long cost;
|
||||
private int materialCost;
|
||||
private final Player player;
|
||||
|
||||
public AnvilUpdateEvent(ItemStack left, ItemStack right, String name, int cost, Player player)
|
||||
{
|
||||
public AnvilUpdateEvent(ItemStack left, ItemStack right, String name, long cost, Player player) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.output = ItemStack.EMPTY;
|
||||
@@ -46,16 +43,14 @@ public class AnvilUpdateEvent extends Event
|
||||
/**
|
||||
* @return The item in the left input (leftmost) anvil slot.
|
||||
*/
|
||||
public ItemStack getLeft()
|
||||
{
|
||||
public ItemStack getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The item in the right input (center) anvil slot.
|
||||
*/
|
||||
public ItemStack getRight()
|
||||
{
|
||||
public ItemStack getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
@@ -65,8 +60,7 @@ public class AnvilUpdateEvent extends Event
|
||||
* @return The name that the output item will be set to, if applicable.
|
||||
*/
|
||||
@Nullable
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -77,8 +71,7 @@ public class AnvilUpdateEvent extends Event
|
||||
* If this event is cancelled, this output stack is discarded.
|
||||
* @return The item to set in the output (rightmost) anvil slot.
|
||||
*/
|
||||
public ItemStack getOutput()
|
||||
{
|
||||
public ItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -86,8 +79,7 @@ public class AnvilUpdateEvent extends Event
|
||||
* Sets the output slot to a specific itemstack.
|
||||
* @param output The stack to change the output to.
|
||||
*/
|
||||
public void setOutput(ItemStack output)
|
||||
{
|
||||
public void setOutput(ItemStack output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@@ -96,8 +88,7 @@ public class AnvilUpdateEvent extends Event
|
||||
* When unchanged, it is guaranteed to be left.getRepairCost() + right.getRepairCost().
|
||||
* @return The level cost of this anvil operation.
|
||||
*/
|
||||
public int getCost()
|
||||
{
|
||||
public long getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
@@ -107,8 +98,7 @@ public class AnvilUpdateEvent extends Event
|
||||
* That is, a player without enough experience may not take the output.
|
||||
* @param cost The new level cost.
|
||||
*/
|
||||
public void setCost(int cost)
|
||||
{
|
||||
public void setCost(long cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
@@ -116,8 +106,7 @@ public class AnvilUpdateEvent extends Event
|
||||
* The material cost is how many units of the right input stack are consumed.
|
||||
* @return The material cost of this anvil operation.
|
||||
*/
|
||||
public int getMaterialCost()
|
||||
{
|
||||
public int getMaterialCost() {
|
||||
return materialCost;
|
||||
}
|
||||
|
||||
@@ -129,16 +118,14 @@ public class AnvilUpdateEvent extends Event
|
||||
* The material cost does not prevent the output from being available.
|
||||
* @param materialCost The new material cost.
|
||||
*/
|
||||
public void setMaterialCost(int materialCost)
|
||||
{
|
||||
public void setMaterialCost(int materialCost) {
|
||||
this.materialCost = materialCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The player using this anvil container.
|
||||
*/
|
||||
public Player getPlayer()
|
||||
{
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
}
|
||||
@@ -19,24 +19,20 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public class DifficultyChangeEvent extends Event
|
||||
{
|
||||
public class DifficultyChangeEvent extends Event {
|
||||
private final Difficulty difficulty;
|
||||
private final Difficulty oldDifficulty;
|
||||
|
||||
public DifficultyChangeEvent(Difficulty difficulty, Difficulty oldDifficulty)
|
||||
{
|
||||
public DifficultyChangeEvent(Difficulty difficulty, Difficulty oldDifficulty) {
|
||||
this.difficulty = difficulty;
|
||||
this.oldDifficulty = oldDifficulty;
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty()
|
||||
{
|
||||
public Difficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public Difficulty getOldDifficulty()
|
||||
{
|
||||
public Difficulty getOldDifficulty() {
|
||||
return oldDifficulty;
|
||||
}
|
||||
}
|
||||
@@ -13,90 +13,116 @@ import java.util.Optional;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
import net.minecraft.server.level.ChunkHolder;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ConfigurationTask;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.repository.RepositorySource;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
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;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.level.LevelSimulatedReader;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.portal.PortalShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.SpawnGroupData;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.MobSpawnType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.monster.Zombie;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ConfigurationTask;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.world.level.BaseSpawner;
|
||||
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.InteractionResult;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.core.BlockPos;
|
||||
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;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.FishingHook;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ClickAction;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.alchemy.PotionBrewing.Builder;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.BaseSpawner;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelSimulatedReader;
|
||||
import net.minecraft.world.level.ServerLevelAccessor;
|
||||
import net.minecraft.world.level.SpawnData;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.storage.ServerLevelData;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.status.ChunkType;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.portal.PortalShape;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import net.minecraft.world.level.storage.ServerLevelData;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.brewing.BrewingRecipeRegisterEvent;
|
||||
import net.minecraftforge.event.brewing.PlayerBrewedPotionEvent;
|
||||
import net.minecraftforge.event.brewing.PotionBrewEvent;
|
||||
import net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
||||
import net.minecraftforge.event.entity.EntityLeaveLevelEvent;
|
||||
import net.minecraftforge.event.entity.EntityMobGriefingEvent;
|
||||
import net.minecraftforge.event.entity.EntityMountEvent;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
@@ -105,37 +131,51 @@ import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
|
||||
import net.minecraftforge.event.entity.ProjectileImpactEvent;
|
||||
import net.minecraftforge.event.entity.item.ItemExpireEvent;
|
||||
import net.minecraftforge.event.entity.living.AnimalTameEvent;
|
||||
import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingBreatheEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingConversionEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDestroyBlockEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDrownEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHealEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingPackSizeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSwapItemsEvent;
|
||||
import net.minecraftforge.event.entity.living.MobEffectEvent;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent;
|
||||
import net.minecraftforge.event.entity.living.ShieldBlockEvent;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent.AllowDespawn;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent.PositionCheck;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent.SpawnPlacementCheck;
|
||||
import net.minecraftforge.event.entity.living.ShieldBlockEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent.ILivingTargetType;
|
||||
import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
|
||||
import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent;
|
||||
import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementProgressEvent;
|
||||
import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementProgressEvent.ProgressType;
|
||||
import net.minecraftforge.event.entity.player.AnvilRepairEvent;
|
||||
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
|
||||
import net.minecraftforge.event.entity.player.ArrowNockEvent;
|
||||
import net.minecraftforge.event.entity.player.BonemealEvent;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemFishedEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PermissionsChangedEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerSetSpawnEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerSpawnPhantomsEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerXpEvent;
|
||||
import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent;
|
||||
import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent;
|
||||
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
|
||||
@@ -150,31 +190,37 @@ import net.minecraftforge.event.level.ChunkEvent;
|
||||
import net.minecraftforge.event.level.ChunkTicketLevelUpdatedEvent;
|
||||
import net.minecraftforge.event.level.ChunkWatchEvent;
|
||||
import net.minecraftforge.event.level.ExplosionEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.event.level.NoteBlockEvent;
|
||||
import net.minecraftforge.event.level.PistonEvent;
|
||||
import net.minecraftforge.event.level.SaplingGrowTreeEvent;
|
||||
import net.minecraftforge.event.level.SleepFinishedTimeEvent;
|
||||
import net.minecraftforge.event.network.ChannelRegistrationChangeEvent;
|
||||
import net.minecraftforge.event.network.ConnectionStartEvent;
|
||||
import net.minecraftforge.event.network.GatherLoginConfigurationTasksEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class ForgeEventFactory {
|
||||
public final class ForgeEventFactory {
|
||||
private ForgeEventFactory() {}
|
||||
|
||||
private static boolean post(Event e) {
|
||||
return MinecraftForge.EVENT_BUS.post(e);
|
||||
}
|
||||
|
||||
private static <E extends Event> E fire(E e) {
|
||||
MinecraftForge.EVENT_BUS.post(e);
|
||||
post(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
private static <T extends Event & IModBusEvent> void postModBus(T e) {
|
||||
ModLoader.get().postEvent(e);
|
||||
}
|
||||
|
||||
public static boolean onMultiBlockPlace(@Nullable Entity entity, List<BlockSnapshot> blockSnapshots, Direction direction) {
|
||||
var snap = blockSnapshots.get(0);
|
||||
var placedAgainst = snap.getLevel().getBlockState(snap.getPos().relative(direction.getOpposite()));
|
||||
@@ -202,7 +248,11 @@ public class ForgeEventFactory {
|
||||
}
|
||||
|
||||
public static void onPlayerDestroyItem(Player player, @NotNull ItemStack stack, @Nullable InteractionHand hand) {
|
||||
post(new PlayerDestroyItemEvent(player, stack, hand));
|
||||
onPlayerDestroyItem(player, stack, LivingEntity.getSlotForHand(hand));
|
||||
}
|
||||
|
||||
public static void onPlayerDestroyItem(Player player, @NotNull ItemStack stack, @Nullable EquipmentSlot slot) {
|
||||
post(new PlayerDestroyItemEvent(player, stack, slot));
|
||||
}
|
||||
|
||||
public static boolean checkSpawnPlacements(EntityType<?> entityType, ServerLevelAccessor level, MobSpawnType spawnType, BlockPos pos, RandomSource random, boolean defaultResult) {
|
||||
@@ -272,12 +322,12 @@ public 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, @Nullable CompoundTag spawnTag) {
|
||||
var event = new MobSpawnEvent.FinalizeSpawn(mob, level, mob.getX(), mob.getY(), mob.getZ(), difficulty, spawnType, spawnData, spawnTag, null);
|
||||
public static SpawnGroupData onFinalizeSpawn(Mob mob, ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType 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)
|
||||
mob.finalizeSpawn(level, event.getDifficulty(), event.getSpawnType(), event.getSpawnData(), event.getSpawnTag());
|
||||
mob.finalizeSpawn(level, event.getDifficulty(), event.getSpawnType(), event.getSpawnData());
|
||||
|
||||
return cancel ? null : event.getSpawnData();
|
||||
}
|
||||
@@ -454,6 +504,10 @@ public class ForgeEventFactory {
|
||||
return post(new AnimalTameEvent(animal, tamer));
|
||||
}
|
||||
|
||||
public static boolean onPlayerPickupXp(Player player, ExperienceOrb orb) {
|
||||
return post(new PlayerXpEvent.PickupXp(player, orb));
|
||||
}
|
||||
|
||||
public static Player.BedSleepingProblem onPlayerSleepInBed(Player player, Optional<BlockPos> pos) {
|
||||
return fire(new PlayerSleepInBedEvent(player, pos)).getResultStatus();
|
||||
}
|
||||
@@ -470,6 +524,10 @@ public class ForgeEventFactory {
|
||||
return post(new PlayerSetSpawnEvent(player, levelKey, pos, forced));
|
||||
}
|
||||
|
||||
public static PlayerSpawnPhantomsEvent onPlayerSpawnPhantom(Player player, int phantomsToSpawn) {
|
||||
return fire(new PlayerSpawnPhantomsEvent(player, phantomsToSpawn));
|
||||
}
|
||||
|
||||
public static void onPlayerClone(Player player, Player oldPlayer, boolean wasDeath) {
|
||||
post(new PlayerEvent.Clone(player, oldPlayer, wasDeath));
|
||||
}
|
||||
@@ -659,6 +717,11 @@ public class ForgeEventFactory {
|
||||
post(new LivingConversionEvent.Post(entity, outcome));
|
||||
}
|
||||
|
||||
public static BabyEntitySpawnEvent onBabySpawn(Mob parentA, Mob parentB, @Nullable AgeableMob proposedChild) {
|
||||
return fire(new BabyEntitySpawnEvent(parentA, parentB, proposedChild));
|
||||
|
||||
}
|
||||
|
||||
public static EntityTeleportEvent.TeleportCommand onEntityTeleportCommand(Entity entity, double targetX, double targetY, double targetZ) {
|
||||
return fire(new EntityTeleportEvent.TeleportCommand(entity, targetX, targetY, targetZ));
|
||||
}
|
||||
@@ -806,9 +869,18 @@ public class ForgeEventFactory {
|
||||
post(new LevelEvent.Load(level));
|
||||
}
|
||||
|
||||
public static void onLevelSave(Level level) {
|
||||
post(new LevelEvent.Save(level));
|
||||
}
|
||||
|
||||
public static void onChunkDataSave(ChunkAccess chunk, LevelAccessor world, CompoundTag data) {
|
||||
post(new ChunkDataEvent.Save(chunk, world, data));
|
||||
}
|
||||
|
||||
public static void onChunkDataLoad(ChunkAccess chunk, CompoundTag data, ChunkType status) {
|
||||
post(new ChunkDataEvent.Load(chunk, data, status));
|
||||
}
|
||||
|
||||
public static void onGameShuttingDown() {
|
||||
post(new GameShuttingDownEvent());
|
||||
}
|
||||
@@ -840,4 +912,145 @@ public class ForgeEventFactory {
|
||||
public static LivingFallEvent onLivingFall(LivingEntity entity, float distance, float damageMultiplier) {
|
||||
return fire(new LivingFallEvent(entity, distance, damageMultiplier));
|
||||
}
|
||||
|
||||
public static LivingBreatheEvent onLivingBreathe(LivingEntity entity, boolean canBreathe, int consumeAirAmount, int refillAirAmount, boolean canRefillAir) {
|
||||
return fire(new LivingBreatheEvent(entity, canBreathe, consumeAirAmount, refillAirAmount, canRefillAir));
|
||||
}
|
||||
|
||||
public static LivingDrownEvent onLivingDrown(LivingEntity entity, boolean isDrowning, float damageAmount, int bubbleCount) {
|
||||
return fire(new LivingDrownEvent(entity, isDrowning, damageAmount, bubbleCount));
|
||||
}
|
||||
|
||||
public static LivingKnockBackEvent onLivingKnockBack(LivingEntity target, float strength, double ratioX, double ratioZ) {
|
||||
return fire(new LivingKnockBackEvent(target, strength, ratioX, ratioZ));
|
||||
}
|
||||
|
||||
public static void onLeftClickEmpty(Player player) {
|
||||
post(new PlayerInteractEvent.LeftClickEmpty(player));
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.LeftClickBlock onLeftClickBlock(Player player, BlockPos pos, Direction face, ServerboundPlayerActionPacket.Action action) {
|
||||
return fire(new PlayerInteractEvent.LeftClickBlock(player, pos, face, PlayerInteractEvent.LeftClickBlock.Action.convert(action)));
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.LeftClickBlock onLeftClickBlockHold(Player player, BlockPos pos, Direction face) {
|
||||
return fire(new PlayerInteractEvent.LeftClickBlock(player, pos, face, PlayerInteractEvent.LeftClickBlock.Action.CLIENT_HOLD));
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.RightClickBlock onRightClickBlock(Player player, InteractionHand hand, BlockPos pos, BlockHitResult hitVec) {
|
||||
return fire(new PlayerInteractEvent.RightClickBlock(player, hand, pos, hitVec));
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.RightClickItem onRightClickItem(Player player, InteractionHand hand) {
|
||||
return fire(new PlayerInteractEvent.RightClickItem(player, hand));
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.EntityInteract onEntityInteract(Player player, Entity entity, InteractionHand hand) {
|
||||
return fire(new PlayerInteractEvent.EntityInteract(player, hand, entity));
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent.EntityInteractSpecific onEntityInteractSpecific(Player player, Entity entity, InteractionHand hand, Vec3 vec3d) {
|
||||
return fire(new PlayerInteractEvent.EntityInteractSpecific(player, hand, entity, vec3d));
|
||||
}
|
||||
|
||||
public static void onRightClickEmpty(Player player, InteractionHand hand) {
|
||||
post(new PlayerInteractEvent.RightClickEmpty(player, hand));
|
||||
}
|
||||
|
||||
// TODO: Remove from mod bus - Lex 04222024
|
||||
public static void addPackFindersServer(Consumer<RepositorySource> consumer) {
|
||||
postModBus(new AddPackFindersEvent(PackType.SERVER_DATA, consumer));
|
||||
}
|
||||
|
||||
public static boolean onEntityJoinLevel(Entity entity, Level level) {
|
||||
return post(new EntityJoinLevelEvent(entity, level));
|
||||
}
|
||||
public static boolean onEntityJoinLevel(Entity entity, Level level, boolean loadedFromDisk) {
|
||||
return post(new EntityJoinLevelEvent(entity, level, loadedFromDisk));
|
||||
}
|
||||
|
||||
public static boolean onEntityLeaveLevel(Entity entity, Level level) {
|
||||
return post(new EntityLeaveLevelEvent(entity, level));
|
||||
}
|
||||
|
||||
public static void onDifficultyChange(Difficulty difficulty, Difficulty oldDifficulty) {
|
||||
post(new DifficultyChangeEvent(difficulty, oldDifficulty));
|
||||
}
|
||||
|
||||
public static void onTagsUpdated(RegistryAccess registryAccess, boolean fromClientPacket, boolean isIntegratedServerConnection) {
|
||||
post(new TagsUpdatedEvent(registryAccess, fromClientPacket, isIntegratedServerConnection));
|
||||
}
|
||||
|
||||
public static boolean onLivingAttackEntity(LivingEntity entity, DamageSource src, float amount) {
|
||||
return post(new LivingAttackEvent(entity, src, amount));
|
||||
}
|
||||
|
||||
public static boolean onVanillaGameEvent(Level level, Holder<GameEvent> vanillaEvent, Vec3 pos, GameEvent.Context context) {
|
||||
return post(new VanillaGameEvent(level, vanillaEvent.get(), pos, context));
|
||||
}
|
||||
|
||||
public static boolean onLivingEffectExpire(LivingEntity entity, MobEffectInstance effect) {
|
||||
return post(new MobEffectEvent.Expired(entity, effect));
|
||||
}
|
||||
|
||||
public static boolean onLivingEffectAdd(LivingEntity entity, MobEffectInstance oldEffect, MobEffectInstance newEffect, Entity source) {
|
||||
return post(new MobEffectEvent.Added(entity, oldEffect, newEffect, source));
|
||||
}
|
||||
|
||||
public static boolean onLivingEffectRemove(LivingEntity entity, MobEffect effect) {
|
||||
return post(new MobEffectEvent.Remove(entity, effect));
|
||||
}
|
||||
|
||||
public static boolean onLivingEffectRemove(LivingEntity entity, MobEffectInstance effect) {
|
||||
return post(new MobEffectEvent.Remove(entity, effect));
|
||||
}
|
||||
|
||||
public static MobEffectEvent.Applicable onLivingEffectCanApply(LivingEntity entity, MobEffectInstance effect) {
|
||||
return fire(new MobEffectEvent.Applicable(entity, effect));
|
||||
}
|
||||
|
||||
public static void onLivingEquipmentChange(LivingEntity entity, EquipmentSlot slot, ItemStack from, ItemStack to) {
|
||||
fire(new LivingEquipmentChangeEvent(entity, slot, from, to));
|
||||
}
|
||||
|
||||
public static LivingChangeTargetEvent onLivingChangeTargetMob(LivingEntity entity, LivingEntity originalTarget) {
|
||||
return fire(new LivingChangeTargetEvent(entity, originalTarget, LivingChangeTargetEvent.LivingTargetType.MOB_TARGET));
|
||||
}
|
||||
|
||||
public static LivingChangeTargetEvent onLivingChangeTargetBehavior(LivingEntity entity, LivingEntity originalTarget) {
|
||||
return fire(new LivingChangeTargetEvent(entity, originalTarget, LivingChangeTargetEvent.LivingTargetType.BEHAVIOR_TARGET));
|
||||
}
|
||||
|
||||
public static ItemFishedEvent onPlayerFishedItem(List<ItemStack> stacks, int rodDamage, FishingHook hook) {
|
||||
return fire(new ItemFishedEvent(stacks, rodDamage, hook));
|
||||
}
|
||||
|
||||
public static PlayerXpEvent.XpChange onPlayerXpChange(Player player, int xp) {
|
||||
return fire(new PlayerXpEvent.XpChange(player, xp));
|
||||
}
|
||||
|
||||
public static PlayerXpEvent.LevelChange onPlayerLevelChange(Player player, int levels) {
|
||||
return fire(new PlayerXpEvent.LevelChange(player, levels));
|
||||
}
|
||||
|
||||
|
||||
public static GrindstoneEvent.OnPlaceItem onGrindstoneChange(@NotNull ItemStack top, @NotNull ItemStack bottom, Container outputSlot, int xp) {
|
||||
return fire(new GrindstoneEvent.OnPlaceItem(top, bottom, xp));
|
||||
}
|
||||
|
||||
public static void onBrewingRecipeRegister(Builder builder, FeatureFlagSet features) {
|
||||
fire(new BrewingRecipeRegisterEvent(builder, features));
|
||||
}
|
||||
|
||||
public static boolean onItemStackedOn(ItemStack carriedItem, ItemStack stackedOnItem, Slot slot, ClickAction action, Player player, SlotAccess carriedSlotAccess) {
|
||||
return post(new ItemStackedOnOtherEvent(carriedItem, stackedOnItem, slot, action, player, carriedSlotAccess));
|
||||
}
|
||||
|
||||
public static NoteBlockEvent.Play onNotePlay(Level world, BlockPos pos, BlockState state, int note, NoteBlockInstrument instrument) {
|
||||
return fire(new NoteBlockEvent.Play(world, pos, state, note, instrument));
|
||||
}
|
||||
|
||||
public static AnvilRepairEvent onAnvilRepair(Player player, @NotNull ItemStack output, @NotNull ItemStack left, @NotNull ItemStack right) {
|
||||
return fire(new AnvilRepairEvent(player, left, right, output));
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import java.util.Collection;
|
||||
* 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;
|
||||
@@ -47,7 +47,7 @@ public class ItemAttributeModifierEvent extends Event
|
||||
* 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;
|
||||
@@ -55,7 +55,7 @@ public class ItemAttributeModifierEvent extends Event
|
||||
|
||||
/**
|
||||
* Returns the attribute map before any changes from other event listeners was made.
|
||||
*/
|
||||
* /
|
||||
public Multimap<Attribute, AttributeModifier> getOriginalModifiers()
|
||||
{
|
||||
return this.originalModifiers;
|
||||
@@ -63,7 +63,7 @@ public class ItemAttributeModifierEvent extends Event
|
||||
|
||||
/**
|
||||
* Gets a modifiable map instance, creating it if the current map is currently unmodifiable
|
||||
*/
|
||||
* /
|
||||
private Multimap<Attribute, AttributeModifier> getModifiableMap()
|
||||
{
|
||||
if (this.modifiableModifiers == null)
|
||||
@@ -81,7 +81,7 @@ public class ItemAttributeModifierEvent extends Event
|
||||
* @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);
|
||||
@@ -92,7 +92,7 @@ public class ItemAttributeModifierEvent extends Event
|
||||
* @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);
|
||||
@@ -102,7 +102,7 @@ public class ItemAttributeModifierEvent extends Event
|
||||
* 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);
|
||||
@@ -110,21 +110,22 @@ public class ItemAttributeModifierEvent extends Event
|
||||
|
||||
/**
|
||||
* Removes all modifiers for all attributes
|
||||
*/
|
||||
* /
|
||||
public void clearModifiers()
|
||||
{
|
||||
getModifiableMap().clear();
|
||||
}
|
||||
|
||||
/** Gets the slot containing this stack */
|
||||
/** Gets the slot containing this stack * /
|
||||
public EquipmentSlot getSlotType()
|
||||
{
|
||||
return this.slotType;
|
||||
}
|
||||
|
||||
/** Gets the item stack instance */
|
||||
/** Gets the item stack instance * /
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -38,8 +38,7 @@ import java.util.Objects;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@Cancelable
|
||||
public class PlayLevelSoundEvent extends Event
|
||||
{
|
||||
public class PlayLevelSoundEvent extends Event {
|
||||
private final Level level;
|
||||
private final float originalVolume;
|
||||
private final float originalPitch;
|
||||
@@ -48,8 +47,7 @@ public class PlayLevelSoundEvent extends Event
|
||||
private float newVolume;
|
||||
private float newPitch;
|
||||
|
||||
public PlayLevelSoundEvent(@NotNull Level level, @NotNull Holder<SoundEvent> sound, @NotNull SoundSource source, float volume, float pitch)
|
||||
{
|
||||
public PlayLevelSoundEvent(@NotNull Level level, @NotNull Holder<SoundEvent> sound, @NotNull SoundSource source, float volume, float pitch) {
|
||||
this.level = level;
|
||||
this.sound = sound;
|
||||
this.source = source;
|
||||
@@ -63,8 +61,7 @@ public class PlayLevelSoundEvent extends Event
|
||||
* {@return the level the sound is being played in}
|
||||
*/
|
||||
@NotNull
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
@@ -72,16 +69,14 @@ public class PlayLevelSoundEvent extends Event
|
||||
* {@return the sound event to be played}
|
||||
*/
|
||||
@Nullable
|
||||
public Holder<SoundEvent> getSound()
|
||||
{
|
||||
public Holder<SoundEvent> getSound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sound event to be played.
|
||||
*/
|
||||
public void setSound(@Nullable Holder<SoundEvent> sound)
|
||||
{
|
||||
public void setSound(@Nullable Holder<SoundEvent> sound) {
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
@@ -89,16 +84,14 @@ public class PlayLevelSoundEvent extends Event
|
||||
* {@return the sound source}
|
||||
*/
|
||||
@NotNull
|
||||
public SoundSource getSource()
|
||||
{
|
||||
public SoundSource getSource() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sound source.
|
||||
*/
|
||||
public void setSource(@NotNull SoundSource source)
|
||||
{
|
||||
public void setSource(@NotNull SoundSource source) {
|
||||
Objects.requireNonNull(source, "Sound source cannot be null");
|
||||
this.source = source;
|
||||
}
|
||||
@@ -106,48 +99,42 @@ public class PlayLevelSoundEvent extends Event
|
||||
/**
|
||||
* {@return the original volume for the sound to be played at}
|
||||
*/
|
||||
public float getOriginalVolume()
|
||||
{
|
||||
public float getOriginalVolume() {
|
||||
return this.originalVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original pitch for the sound to be played at}
|
||||
*/
|
||||
public float getOriginalPitch()
|
||||
{
|
||||
public float getOriginalPitch() {
|
||||
return this.originalPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the volume the sound will be played at}
|
||||
*/
|
||||
public float getNewVolume()
|
||||
{
|
||||
public float getNewVolume() {
|
||||
return this.newVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume the sound will be played at.
|
||||
*/
|
||||
public void setNewVolume(float newVolume)
|
||||
{
|
||||
public void setNewVolume(float newVolume) {
|
||||
this.newVolume = newVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pitch the sound will be played at}
|
||||
*/
|
||||
public float getNewPitch()
|
||||
{
|
||||
public float getNewPitch() {
|
||||
return this.newPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pitch the sound will be played at.
|
||||
*/
|
||||
public void setNewPitch(float newPitch)
|
||||
{
|
||||
public void setNewPitch(float newPitch) {
|
||||
this.newPitch = newPitch;
|
||||
}
|
||||
|
||||
@@ -162,12 +149,10 @@ public class PlayLevelSoundEvent extends Event
|
||||
* <p>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public static class AtEntity extends PlayLevelSoundEvent
|
||||
{
|
||||
public static class AtEntity extends PlayLevelSoundEvent {
|
||||
private final Entity entity;
|
||||
|
||||
public AtEntity(Entity entity, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch)
|
||||
{
|
||||
public AtEntity(Entity entity, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch) {
|
||||
super(entity.level(), sound, source, volume, pitch);
|
||||
this.entity = entity;
|
||||
}
|
||||
@@ -175,8 +160,7 @@ public class PlayLevelSoundEvent extends Event
|
||||
/**
|
||||
* {@return the entity the sound is being played on}
|
||||
*/
|
||||
public Entity getEntity()
|
||||
{
|
||||
public Entity getEntity() {
|
||||
return this.entity;
|
||||
}
|
||||
}
|
||||
@@ -192,12 +176,10 @@ public class PlayLevelSoundEvent extends Event
|
||||
* <p>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public static class AtPosition extends PlayLevelSoundEvent
|
||||
{
|
||||
public static class AtPosition extends PlayLevelSoundEvent {
|
||||
private final Vec3 position;
|
||||
|
||||
public AtPosition(Level level, Vec3 position, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch)
|
||||
{
|
||||
public AtPosition(Level level, Vec3 position, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch) {
|
||||
super(level, sound, source, volume, pitch);
|
||||
this.position = position;
|
||||
}
|
||||
@@ -205,8 +187,7 @@ public class PlayLevelSoundEvent extends Event
|
||||
/**
|
||||
* {@return the position the sound is being played at}
|
||||
*/
|
||||
public Vec3 getPosition()
|
||||
{
|
||||
public Vec3 getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.brewing;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.alchemy.PotionBrewing;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraftforge.common.brewing.BrewingRecipe;
|
||||
import net.minecraftforge.common.brewing.IBrewingRecipe;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
public class BrewingRecipeRegisterEvent extends Event {
|
||||
private final PotionBrewing.Builder builder;
|
||||
private final FeatureFlagSet features;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BrewingRecipeRegisterEvent(PotionBrewing.Builder builder, FeatureFlagSet features) {
|
||||
this.builder = builder;
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
public PotionBrewing.Builder getBuilder() {
|
||||
return this.builder;
|
||||
}
|
||||
|
||||
public FeatureFlagSet getFeatures() {
|
||||
return this.features;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a recipe to the registry. Due to the nature of the brewing stand
|
||||
* inputs that stack (a.k.a max stack size > 1) are not allowed.
|
||||
*
|
||||
* @param input
|
||||
* The Ingredient that goes in same slots as the water bottles
|
||||
* would.
|
||||
* @param ingredient
|
||||
* The Ingredient that goes in the same slot as nether wart would.
|
||||
* @param output
|
||||
* The ItemStack that will replace the input once the brewing is
|
||||
* done.
|
||||
*/
|
||||
public void addRecipe(Ingredient input, Ingredient ingredient, ItemStack output) {
|
||||
addRecipe(new BrewingRecipe(input, ingredient, output));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a recipe to the registry. Due to the nature of the brewing stand
|
||||
* inputs that stack (a.k.a max stack size > 1) are not allowed.
|
||||
*/
|
||||
public void addRecipe(IBrewingRecipe recipe) {
|
||||
getBuilder().add(recipe);
|
||||
}
|
||||
}
|
||||
+10
-16
@@ -6,6 +6,8 @@
|
||||
package net.minecraftforge.event.entity;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
@@ -26,14 +28,12 @@ import java.util.stream.Collectors;
|
||||
* <br>
|
||||
* Fired on the Mod bus {@link IModBusEvent}.<br>
|
||||
**/
|
||||
public class EntityAttributeModificationEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public class EntityAttributeModificationEvent extends Event implements IModBusEvent {
|
||||
private final Map<EntityType<? extends LivingEntity>, AttributeSupplier.Builder> entityAttributes;
|
||||
private final List<EntityType<? extends LivingEntity>> entityTypes;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EntityAttributeModificationEvent(Map<EntityType<? extends LivingEntity>, AttributeSupplier.Builder> mapIn)
|
||||
{
|
||||
public EntityAttributeModificationEvent(Map<EntityType<? extends LivingEntity>, AttributeSupplier.Builder> mapIn) {
|
||||
this.entityAttributes = mapIn;
|
||||
this.entityTypes = ImmutableList.copyOf(
|
||||
ForgeRegistries.ENTITY_TYPES.getValues().stream()
|
||||
@@ -43,27 +43,21 @@ public class EntityAttributeModificationEvent extends Event implements IModBusEv
|
||||
);
|
||||
}
|
||||
|
||||
public void add(EntityType<? extends LivingEntity> entityType, Attribute attribute, double value)
|
||||
{
|
||||
AttributeSupplier.Builder attributes = entityAttributes.computeIfAbsent(entityType,
|
||||
(type) -> new AttributeSupplier.Builder());
|
||||
public void add(EntityType<? extends LivingEntity> entityType, Holder<Attribute> attribute, double value) {
|
||||
var attributes = entityAttributes.computeIfAbsent(entityType, (type) -> new AttributeSupplier.Builder());
|
||||
attributes.add(attribute, value);
|
||||
}
|
||||
|
||||
public void add(EntityType<? extends LivingEntity> entityType, Attribute attribute)
|
||||
{
|
||||
add(entityType, attribute, attribute.getDefaultValue());
|
||||
public void add(EntityType<? extends LivingEntity> entityType, Holder<Attribute> attribute) {
|
||||
add(entityType, attribute, attribute.get().getDefaultValue());
|
||||
}
|
||||
|
||||
public boolean has(EntityType<? extends LivingEntity> entityType, Attribute attribute)
|
||||
{
|
||||
public boolean has(EntityType<? extends LivingEntity> entityType, Holder<Attribute> attribute) {
|
||||
AttributeSupplier globalMap = DefaultAttributes.getSupplier(entityType);
|
||||
return globalMap.hasAttribute(attribute) || (entityAttributes.get(entityType) != null && entityAttributes.get(entityType).hasAttribute(attribute));
|
||||
}
|
||||
|
||||
public List<EntityType<? extends LivingEntity>> getTypes()
|
||||
{
|
||||
public List<EntityType<? extends LivingEntity>> getTypes() {
|
||||
return entityTypes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.event.entity;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
@@ -28,18 +27,15 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
* on both logical sides.
|
||||
**/
|
||||
@Cancelable
|
||||
public class EntityJoinLevelEvent extends EntityEvent
|
||||
{
|
||||
public class EntityJoinLevelEvent extends EntityEvent {
|
||||
private final Level level;
|
||||
private final boolean loadedFromDisk;
|
||||
|
||||
public EntityJoinLevelEvent(Entity entity, Level level)
|
||||
{
|
||||
public EntityJoinLevelEvent(Entity entity, Level level) {
|
||||
this(entity, level, false);
|
||||
}
|
||||
|
||||
public EntityJoinLevelEvent(Entity entity, Level level, boolean loadedFromDisk)
|
||||
{
|
||||
public EntityJoinLevelEvent(Entity entity, Level level, boolean loadedFromDisk) {
|
||||
super(entity);
|
||||
this.level = level;
|
||||
this.loadedFromDisk = loadedFromDisk;
|
||||
@@ -48,8 +44,7 @@ public class EntityJoinLevelEvent extends EntityEvent
|
||||
/**
|
||||
* {@return the level that the entity is set to join}
|
||||
*/
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@@ -57,8 +52,7 @@ public class EntityJoinLevelEvent extends EntityEvent
|
||||
* @return {@code true} if the entity was loaded from disk, {@code false} otherwise.
|
||||
* On the {@linkplain LogicalSide#CLIENT logical client}, this will always return {@code false}.
|
||||
*/
|
||||
public boolean loadedFromDisk()
|
||||
{
|
||||
public boolean loadedFromDisk() {
|
||||
return loadedFromDisk;
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,10 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
|
||||
* on both logical sides.
|
||||
**/
|
||||
public class EntityLeaveLevelEvent extends EntityEvent
|
||||
{
|
||||
public class EntityLeaveLevelEvent extends EntityEvent {
|
||||
private final Level level;
|
||||
|
||||
public EntityLeaveLevelEvent(Entity entity, Level level)
|
||||
{
|
||||
public EntityLeaveLevelEvent(Entity entity, Level level) {
|
||||
super(entity);
|
||||
this.level = level;
|
||||
}
|
||||
@@ -33,8 +31,7 @@ public class EntityLeaveLevelEvent extends EntityEvent
|
||||
/**
|
||||
* {@return the level the entity is set to leave}
|
||||
*/
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.SpawnPlacementType;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.SpawnPlacements;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
@@ -41,29 +42,25 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
*
|
||||
* Fired on the Mod bus {@link IModBusEvent}.<br>
|
||||
*/
|
||||
public class SpawnPlacementRegisterEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public class SpawnPlacementRegisterEvent extends Event implements IModBusEvent {
|
||||
private final Map<EntityType<?>, MergedSpawnPredicate<?>> map;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public SpawnPlacementRegisterEvent(Map<EntityType<?>, MergedSpawnPredicate<?>> map)
|
||||
{
|
||||
public SpawnPlacementRegisterEvent(Map<EntityType<?>, MergedSpawnPredicate<?>> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an optional spawn placement {@code predicate} for a given {@code entityType}
|
||||
*/
|
||||
public <T extends Entity> void register(EntityType<T> entityType, SpawnPlacements.SpawnPredicate<T> predicate)
|
||||
{
|
||||
public <T extends Entity> void register(EntityType<T> entityType, SpawnPlacements.SpawnPredicate<T> predicate) {
|
||||
register(entityType, null, null, predicate, Operation.OR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@code predicate} for a given {@code entityType} with a given {@code operation} for handling
|
||||
*/
|
||||
public <T extends Entity> void register(EntityType<T> entityType, SpawnPlacements.SpawnPredicate<T> predicate, Operation operation)
|
||||
{
|
||||
public <T extends Entity> void register(EntityType<T> entityType, SpawnPlacements.SpawnPredicate<T> predicate, Operation operation) {
|
||||
register(entityType, null, null, predicate, operation);
|
||||
}
|
||||
|
||||
@@ -73,32 +70,27 @@ public class SpawnPlacementRegisterEvent extends Event implements IModBusEvent
|
||||
* Use {@code null} for the placement or heightmap to leave them as is (which should be done in almost every case)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Entity> void register(EntityType<T> entityType, @Nullable SpawnPlacements.Type placementType, @Nullable Heightmap.Types heightmap, SpawnPlacements.SpawnPredicate<T> predicate, Operation operation)
|
||||
{
|
||||
if (!map.containsKey(entityType))
|
||||
{
|
||||
if (placementType == null)
|
||||
{
|
||||
public <T extends Entity> void register(EntityType<T> entityType, @Nullable SpawnPlacementType placementType, @Nullable Heightmap.Types heightmap, SpawnPlacements.SpawnPredicate<T> predicate, Operation operation) {
|
||||
if (!map.containsKey(entityType)) {
|
||||
if (placementType == null) {
|
||||
throw new NullPointerException("Registering a new Spawn Predicate requires a nonnull placement type! Entity Type: " + ForgeRegistries.ENTITY_TYPES.getKey(entityType));
|
||||
}
|
||||
if (heightmap == null)
|
||||
{
|
||||
|
||||
if (heightmap == null) {
|
||||
throw new NullPointerException("Registering a new Spawn Predicate requires a nonnull heightmap type! Entity Type: "+ ForgeRegistries.ENTITY_TYPES.getKey(entityType));
|
||||
}
|
||||
|
||||
map.put(entityType, new MergedSpawnPredicate<>(predicate, placementType, heightmap));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (operation != Operation.REPLACE && (heightmap != null || placementType != null))
|
||||
{
|
||||
} else {
|
||||
if (operation != Operation.REPLACE && (heightmap != null || placementType != null)) {
|
||||
throw new IllegalStateException("Nonnull heightmap types or spawn placement types may only be used with the REPLACE operation. Entity Type: "+ ForgeRegistries.ENTITY_TYPES.getKey(entityType));
|
||||
}
|
||||
|
||||
((MergedSpawnPredicate<T>) map.get(entityType)).merge(operation, predicate, placementType, heightmap);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Operation
|
||||
{
|
||||
public enum Operation {
|
||||
/**
|
||||
* Checked third, these predicates must all pass along with the original predicate
|
||||
*/
|
||||
@@ -113,17 +105,15 @@ public class SpawnPlacementRegisterEvent extends Event implements IModBusEvent
|
||||
REPLACE
|
||||
}
|
||||
|
||||
public static class MergedSpawnPredicate<T extends Entity>
|
||||
{
|
||||
public static class MergedSpawnPredicate<T extends Entity> {
|
||||
private final SpawnPlacements.SpawnPredicate<T> originalPredicate;
|
||||
private final List<SpawnPlacements.SpawnPredicate<T>> orPredicates;
|
||||
private final List<SpawnPlacements.SpawnPredicate<T>> andPredicates;
|
||||
@Nullable private SpawnPlacements.SpawnPredicate<T> replacementPredicate;
|
||||
private SpawnPlacements.Type spawnType;
|
||||
private SpawnPlacementType spawnType;
|
||||
private Heightmap.Types heightmapType;
|
||||
|
||||
public MergedSpawnPredicate(SpawnPlacements.SpawnPredicate<T> originalPredicate, SpawnPlacements.Type spawnType, Heightmap.Types heightmapType)
|
||||
{
|
||||
public MergedSpawnPredicate(SpawnPlacements.SpawnPredicate<T> originalPredicate, SpawnPlacementType spawnType, Heightmap.Types heightmapType) {
|
||||
this.originalPredicate = originalPredicate;
|
||||
this.orPredicates = new ArrayList<>();
|
||||
this.andPredicates = new ArrayList<>();
|
||||
@@ -132,58 +122,46 @@ public class SpawnPlacementRegisterEvent extends Event implements IModBusEvent
|
||||
this.heightmapType = heightmapType;
|
||||
}
|
||||
|
||||
public SpawnPlacements.Type getSpawnType()
|
||||
{
|
||||
public SpawnPlacementType getSpawnType() {
|
||||
return spawnType;
|
||||
}
|
||||
|
||||
public Heightmap.Types getHeightmapType()
|
||||
{
|
||||
public Heightmap.Types getHeightmapType() {
|
||||
return heightmapType;
|
||||
}
|
||||
|
||||
private void merge(Operation operation, SpawnPlacements.SpawnPredicate<T> predicate, @Nullable SpawnPlacements.Type spawnType, @Nullable Heightmap.Types heightmapType)
|
||||
{
|
||||
if (operation == Operation.AND)
|
||||
{
|
||||
private void merge(Operation operation, SpawnPlacements.SpawnPredicate<T> predicate, @Nullable SpawnPlacementType spawnType, @Nullable Heightmap.Types heightmapType) {
|
||||
if (operation == Operation.AND) {
|
||||
andPredicates.add(predicate);
|
||||
}
|
||||
else if (operation == Operation.OR)
|
||||
{
|
||||
} else if (operation == Operation.OR) {
|
||||
orPredicates.add(predicate);
|
||||
}
|
||||
else if (operation == Operation.REPLACE)
|
||||
{
|
||||
} else if (operation == Operation.REPLACE) {
|
||||
replacementPredicate = predicate;
|
||||
if (spawnType != null)
|
||||
{
|
||||
if (spawnType != null) {
|
||||
this.spawnType = spawnType;
|
||||
}
|
||||
if (heightmapType != null)
|
||||
{
|
||||
|
||||
if (heightmapType != null) {
|
||||
this.heightmapType = heightmapType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public SpawnPlacements.SpawnPredicate<T> build()
|
||||
{
|
||||
if (replacementPredicate != null)
|
||||
{
|
||||
public SpawnPlacements.SpawnPredicate<T> build() {
|
||||
if (replacementPredicate != null) {
|
||||
return replacementPredicate;
|
||||
}
|
||||
|
||||
final var original = originalPredicate;
|
||||
|
||||
final SpawnPlacements.SpawnPredicate<T> compiledOrPredicate = (entityType, level, spawnType, pos, random) -> {
|
||||
if (original.test(entityType, level, spawnType, pos, random))
|
||||
{
|
||||
if (original.test(entityType, level, spawnType, pos, random)) {
|
||||
return true;
|
||||
}
|
||||
for (SpawnPlacements.SpawnPredicate<T> predicate : orPredicates)
|
||||
{
|
||||
if (predicate.test(entityType, level, spawnType, pos, random))
|
||||
{
|
||||
|
||||
for (SpawnPlacements.SpawnPredicate<T> predicate : orPredicates) {
|
||||
if (predicate.test(entityType, level, spawnType, pos, random)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -191,14 +169,12 @@ public class SpawnPlacementRegisterEvent extends Event implements IModBusEvent
|
||||
};
|
||||
|
||||
final SpawnPlacements.SpawnPredicate<T> compiledAndPredicate = (entityType, level, spawnType, pos, random) -> {
|
||||
if (!compiledOrPredicate.test(entityType, level, spawnType, pos, random))
|
||||
{
|
||||
if (!compiledOrPredicate.test(entityType, level, spawnType, pos, random)) {
|
||||
return false;
|
||||
}
|
||||
for (SpawnPlacements.SpawnPredicate<T> predicate : andPredicates)
|
||||
{
|
||||
if (!predicate.test(entityType, level, spawnType, pos, random))
|
||||
{
|
||||
|
||||
for (SpawnPlacements.SpawnPredicate<T> predicate : andPredicates) {
|
||||
if (!predicate.test(entityType, level, spawnType, pos, random)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -208,5 +184,4 @@ public class SpawnPlacementRegisterEvent extends Event implements IModBusEvent
|
||||
return compiledAndPredicate;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import net.minecraft.world.entity.animal.Fox;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -36,24 +38,21 @@ import org.jetbrains.annotations.Nullable;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public class BabyEntitySpawnEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
public class BabyEntitySpawnEvent extends Event {
|
||||
private final Mob parentA;
|
||||
private final Mob parentB;
|
||||
private final Player causedByPlayer;
|
||||
private AgeableMob child;
|
||||
|
||||
public BabyEntitySpawnEvent(Mob parentA, Mob parentB, @Nullable AgeableMob proposedChild)
|
||||
{
|
||||
public BabyEntitySpawnEvent(Mob parentA, Mob parentB, @Nullable AgeableMob proposedChild) {
|
||||
//causedByPlayer calculated here to simplify the patch.
|
||||
Player causedByPlayer = null;
|
||||
if (parentA instanceof Animal) {
|
||||
causedByPlayer = ((Animal)parentA).getLoveCause();
|
||||
if (parentA instanceof Animal animal) {
|
||||
causedByPlayer = animal.getLoveCause();
|
||||
}
|
||||
|
||||
if (causedByPlayer == null && parentB instanceof Animal)
|
||||
{
|
||||
causedByPlayer = ((Animal)parentB).getLoveCause();
|
||||
if (causedByPlayer == null && parentB instanceof Animal animal) {
|
||||
causedByPlayer = animal.getLoveCause();
|
||||
}
|
||||
|
||||
this.parentA = parentA;
|
||||
@@ -62,30 +61,25 @@ public class BabyEntitySpawnEvent extends net.minecraftforge.eventbus.api.Event
|
||||
this.child = proposedChild;
|
||||
}
|
||||
|
||||
public Mob getParentA()
|
||||
{
|
||||
public Mob getParentA() {
|
||||
return parentA;
|
||||
}
|
||||
|
||||
public Mob getParentB()
|
||||
{
|
||||
public Mob getParentB() {
|
||||
return parentB;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Player getCausedByPlayer()
|
||||
{
|
||||
public Player getCausedByPlayer() {
|
||||
return causedByPlayer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public AgeableMob getChild()
|
||||
{
|
||||
public AgeableMob getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(AgeableMob proposedChild)
|
||||
{
|
||||
public void setChild(AgeableMob proposedChild) {
|
||||
child = proposedChild;
|
||||
}
|
||||
}
|
||||
@@ -29,12 +29,6 @@ public class LivingBreatheEvent extends LivingEvent {
|
||||
private int consumeAirAmount;
|
||||
private int refillAirAmount;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
public LivingBreatheEvent(LivingEntity entity, boolean canBreathe, int consumeAirAmount, int refillAirAmount) {
|
||||
this(entity, canBreathe, consumeAirAmount, refillAirAmount, canBreathe);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public LivingBreatheEvent(LivingEntity entity, boolean canBreathe, int consumeAirAmount, int refillAirAmount, boolean canRefillAir) {
|
||||
super(entity);
|
||||
|
||||
@@ -34,14 +34,12 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@Cancelable
|
||||
public class LivingChangeTargetEvent extends LivingEvent
|
||||
{
|
||||
public class LivingChangeTargetEvent extends LivingEvent {
|
||||
private final ILivingTargetType targetType;
|
||||
private final LivingEntity originalTarget;
|
||||
private LivingEntity newTarget;
|
||||
|
||||
public LivingChangeTargetEvent(LivingEntity entity, LivingEntity originalTarget, ILivingTargetType targetType)
|
||||
{
|
||||
|
||||
public LivingChangeTargetEvent(LivingEntity entity, LivingEntity originalTarget, ILivingTargetType targetType) {
|
||||
super(entity);
|
||||
this.originalTarget = originalTarget;
|
||||
this.newTarget = originalTarget;
|
||||
@@ -51,8 +49,7 @@ public class LivingChangeTargetEvent extends LivingEvent
|
||||
/**
|
||||
* {@return the new target of this entity.}
|
||||
*/
|
||||
public LivingEntity getNewTarget()
|
||||
{
|
||||
public LivingEntity getNewTarget() {
|
||||
return newTarget;
|
||||
}
|
||||
|
||||
@@ -60,43 +57,36 @@ public class LivingChangeTargetEvent extends LivingEvent
|
||||
* Sets the new target this entity shall have.
|
||||
* @param newTarget The new target of this entity.
|
||||
*/
|
||||
public void setNewTarget(LivingEntity newTarget)
|
||||
{
|
||||
public void setNewTarget(LivingEntity newTarget) {
|
||||
this.newTarget = newTarget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@return the living target type.}
|
||||
*/
|
||||
public ILivingTargetType getTargetType()
|
||||
{
|
||||
public ILivingTargetType getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original entity MC intended to use as a target before firing this event.}
|
||||
*/
|
||||
public LivingEntity getOriginalTarget()
|
||||
{
|
||||
public LivingEntity getOriginalTarget() {
|
||||
return originalTarget;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A living target type indicates what kind of system caused a change of
|
||||
* targets. For a list of default target types, take a look at
|
||||
* {@link LivingTargetType}.
|
||||
*/
|
||||
public static interface ILivingTargetType
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static interface ILivingTargetType { }
|
||||
|
||||
/**
|
||||
* This enum contains two default living target types.
|
||||
*/
|
||||
public static enum LivingTargetType implements ILivingTargetType
|
||||
{
|
||||
public static enum LivingTargetType implements ILivingTargetType {
|
||||
/**
|
||||
* This target type indicates that the target has been set by calling {@link Mob#setTarget(LivingEntity)}.
|
||||
*/
|
||||
|
||||
@@ -47,13 +47,6 @@ public class LivingDrownEvent extends LivingEvent {
|
||||
this.bubbleCount = bubbleCount;
|
||||
}
|
||||
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
public LivingDrownEvent(LivingEntity entity, boolean isDrowning) {
|
||||
this(entity, isDrowning, 2.0F, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns true if the entity is "actively" drowning.<br>
|
||||
* For most entities, this happens when their air supply reaches -20.<br>
|
||||
|
||||
+13
-7
@@ -28,23 +28,29 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public class LivingEquipmentChangeEvent extends LivingEvent
|
||||
{
|
||||
public class LivingEquipmentChangeEvent extends LivingEvent {
|
||||
private final EquipmentSlot slot;
|
||||
private final ItemStack from;
|
||||
private final ItemStack to;
|
||||
|
||||
public LivingEquipmentChangeEvent(LivingEntity entity, EquipmentSlot slot, @NotNull ItemStack from, @NotNull ItemStack to)
|
||||
{
|
||||
public LivingEquipmentChangeEvent(LivingEntity entity, EquipmentSlot slot, @NotNull ItemStack from, @NotNull ItemStack to) {
|
||||
super(entity);
|
||||
this.slot = slot;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public EquipmentSlot getSlot() { return this.slot; }
|
||||
public EquipmentSlot getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getFrom() { return this.from; }
|
||||
public ItemStack getFrom() {
|
||||
return this.from;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getTo() { return this.to; }
|
||||
public ItemStack getTo() {
|
||||
return this.to;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
@@ -19,20 +20,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <p>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public class MobEffectEvent extends LivingEvent
|
||||
{
|
||||
public class MobEffectEvent extends LivingEvent {
|
||||
@Nullable
|
||||
protected final MobEffectInstance effectInstance;
|
||||
|
||||
public MobEffectEvent(LivingEntity living, MobEffectInstance effectInstance)
|
||||
{
|
||||
public MobEffectEvent(LivingEntity living, MobEffectInstance effectInstance) {
|
||||
super(living);
|
||||
this.effectInstance = effectInstance;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MobEffectInstance getEffectInstance()
|
||||
{
|
||||
public MobEffectInstance getEffectInstance() {
|
||||
return effectInstance;
|
||||
}
|
||||
|
||||
@@ -42,27 +40,23 @@ public class MobEffectEvent extends LivingEvent
|
||||
* This Event does not have a result.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Remove extends MobEffectEvent
|
||||
{
|
||||
public static class Remove extends MobEffectEvent {
|
||||
private final MobEffect effect;
|
||||
|
||||
public Remove(LivingEntity living, MobEffect effect)
|
||||
{
|
||||
super(living, living.getEffect(effect));
|
||||
public Remove(LivingEntity living, MobEffect effect) {
|
||||
super(living, living.getEffect(BuiltInRegistries.MOB_EFFECT.wrapAsHolder(effect)));
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
public Remove(LivingEntity living, MobEffectInstance effectInstance)
|
||||
{
|
||||
public Remove(LivingEntity living, MobEffectInstance effectInstance) {
|
||||
super(living, effectInstance);
|
||||
this.effect = effectInstance.getEffect();
|
||||
this.effect = effectInstance.getEffect().get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link MobEffectEvent} which is being removed from the entity
|
||||
*/
|
||||
public MobEffect getEffect()
|
||||
{
|
||||
public MobEffect getEffect() {
|
||||
return this.effect;
|
||||
}
|
||||
|
||||
@@ -71,8 +65,7 @@ public class MobEffectEvent extends LivingEvent
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public MobEffectInstance getEffectInstance()
|
||||
{
|
||||
public MobEffectInstance getEffectInstance() {
|
||||
return super.getEffectInstance();
|
||||
}
|
||||
}
|
||||
@@ -87,17 +80,14 @@ public class MobEffectEvent extends LivingEvent
|
||||
* {@link Result#DEFAULT DEFAULT} will run vanilla logic to determine if this mob effect is applicable in {@link LivingEntity#canBeAffected}.
|
||||
*/
|
||||
@HasResult
|
||||
public static class Applicable extends MobEffectEvent
|
||||
{
|
||||
public Applicable(LivingEntity living, @NotNull MobEffectInstance effectInstance)
|
||||
{
|
||||
public static class Applicable extends MobEffectEvent {
|
||||
public Applicable(LivingEntity living, @NotNull MobEffectInstance effectInstance) {
|
||||
super(living, effectInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public MobEffectInstance getEffectInstance()
|
||||
{
|
||||
public MobEffectInstance getEffectInstance() {
|
||||
return super.getEffectInstance();
|
||||
}
|
||||
}
|
||||
@@ -108,13 +98,11 @@ public class MobEffectEvent extends LivingEvent
|
||||
* This event is not {@link Cancelable}.
|
||||
* This event does not have a result.
|
||||
*/
|
||||
public static class Added extends MobEffectEvent
|
||||
{
|
||||
public static class Added extends MobEffectEvent {
|
||||
private final MobEffectInstance oldEffectInstance;
|
||||
private final Entity source;
|
||||
|
||||
public Added(LivingEntity living, MobEffectInstance oldEffectInstance, MobEffectInstance newEffectInstance, Entity source)
|
||||
{
|
||||
public Added(LivingEntity living, MobEffectInstance oldEffectInstance, MobEffectInstance newEffectInstance, Entity source) {
|
||||
super(living, newEffectInstance);
|
||||
this.oldEffectInstance = oldEffectInstance;
|
||||
this.source = source;
|
||||
@@ -125,8 +113,7 @@ public class MobEffectEvent extends LivingEvent
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public MobEffectInstance getEffectInstance()
|
||||
{
|
||||
public MobEffectInstance getEffectInstance() {
|
||||
return super.getEffectInstance();
|
||||
}
|
||||
|
||||
@@ -134,8 +121,7 @@ public class MobEffectEvent extends LivingEvent
|
||||
* @return the old {@link MobEffectInstance}. This can be null if the entity did not have an effect of this kind before.
|
||||
*/
|
||||
@Nullable
|
||||
public MobEffectInstance getOldEffectInstance()
|
||||
{
|
||||
public MobEffectInstance getOldEffectInstance() {
|
||||
return oldEffectInstance;
|
||||
}
|
||||
|
||||
@@ -143,8 +129,7 @@ public class MobEffectEvent extends LivingEvent
|
||||
* @return the entity source of the effect, or {@code null} if none exists
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getEffectSource()
|
||||
{
|
||||
public Entity getEffectSource() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -154,11 +139,9 @@ public class MobEffectEvent extends LivingEvent
|
||||
* This event is not {@link Cancelable}.
|
||||
* This event does not have a result.
|
||||
*/
|
||||
public static class Expired extends MobEffectEvent
|
||||
{
|
||||
public Expired(LivingEntity living, MobEffectInstance effectInstance)
|
||||
{
|
||||
super(living, effectInstance);
|
||||
public static class Expired extends MobEffectEvent {
|
||||
public Expired(LivingEntity living, MobEffectInstance effect) {
|
||||
super(living, effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
* Fires after Potion Color Calculation.
|
||||
*
|
||||
* this event is not {@link Cancelable}
|
||||
*
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public class PotionColorCalculationEvent extends LivingEvent
|
||||
{
|
||||
private int color;
|
||||
private boolean hideParticle;
|
||||
private final Collection<MobEffectInstance> effectList;
|
||||
|
||||
public PotionColorCalculationEvent(LivingEntity entity, int color, boolean hideParticle,
|
||||
Collection<MobEffectInstance> effectList)
|
||||
{
|
||||
super(entity);
|
||||
this.color = color;
|
||||
this.effectList = effectList;
|
||||
this.hideParticle = hideParticle;
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(int color)
|
||||
{
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public boolean areParticlesHidden()
|
||||
{
|
||||
return hideParticle;
|
||||
}
|
||||
|
||||
public void shouldHideParticles(boolean hideParticle)
|
||||
{
|
||||
this.hideParticle = hideParticle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that returned list is unmodifiable.
|
||||
*
|
||||
* @return effects
|
||||
*/
|
||||
public Collection<MobEffectInstance> getEffects()
|
||||
{
|
||||
return Collections.unmodifiableCollection(effectList);
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,12 @@ import java.util.List;
|
||||
* The hook will still take the damage specified
|
||||
*/
|
||||
@Cancelable
|
||||
public class ItemFishedEvent extends PlayerEvent
|
||||
{
|
||||
public class ItemFishedEvent extends PlayerEvent {
|
||||
private final NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
private final FishingHook hook;
|
||||
private int rodDamage;
|
||||
|
||||
public ItemFishedEvent(List<ItemStack> stacks, int rodDamage, FishingHook hook)
|
||||
{
|
||||
public ItemFishedEvent(List<ItemStack> stacks, int rodDamage, FishingHook hook) {
|
||||
super(hook.getPlayerOwner());
|
||||
this.stacks.addAll(stacks);
|
||||
this.rodDamage = rodDamage;
|
||||
@@ -40,8 +38,7 @@ public class ItemFishedEvent extends PlayerEvent
|
||||
* Get the damage the rod will take.
|
||||
* @return The damage the rod will take
|
||||
*/
|
||||
public int getRodDamage()
|
||||
{
|
||||
public int getRodDamage() {
|
||||
return rodDamage;
|
||||
}
|
||||
|
||||
@@ -50,8 +47,7 @@ public class ItemFishedEvent extends PlayerEvent
|
||||
* This is not added to the pre-existing damage to be taken.
|
||||
* @param rodDamage The damage the rod will take. Must be nonnegative
|
||||
*/
|
||||
public void damageRodBy(@Nonnegative int rodDamage)
|
||||
{
|
||||
public void damageRodBy(@Nonnegative int rodDamage) {
|
||||
Preconditions.checkArgument(rodDamage >= 0);
|
||||
this.rodDamage = rodDamage;
|
||||
}
|
||||
@@ -61,16 +57,14 @@ public class ItemFishedEvent extends PlayerEvent
|
||||
* You cannot use this to modify the drops the player will get.
|
||||
* If you want to affect the loot, you should use LootTables.
|
||||
*/
|
||||
public NonNullList<ItemStack> getDrops()
|
||||
{
|
||||
public NonNullList<ItemStack> getDrops() {
|
||||
return stacks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to stuff related to the hook itself, like the position of the bobber.
|
||||
*/
|
||||
public FishingHook getHookEntity()
|
||||
{
|
||||
public FishingHook getHookEntity() {
|
||||
return hook;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
@@ -47,22 +48,26 @@ import org.jetbrains.annotations.Nullable;
|
||||
* This event is fired from {@link ForgeEventFactory#onPlayerDestroyItem(Player, ItemStack, InteractionHand)}.<br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public class PlayerDestroyItemEvent extends PlayerEvent
|
||||
{
|
||||
public class PlayerDestroyItemEvent extends PlayerEvent {
|
||||
@NotNull
|
||||
private final ItemStack original;
|
||||
@Nullable
|
||||
private final InteractionHand hand; // May be null if this player destroys the item by any use besides holding it.
|
||||
public PlayerDestroyItemEvent(Player player, @NotNull ItemStack original, @Nullable InteractionHand hand)
|
||||
{
|
||||
private final EquipmentSlot slot; // May be null if this player destroys the item by any use besides holding it.
|
||||
|
||||
public PlayerDestroyItemEvent(Player player, @NotNull ItemStack original, @Nullable EquipmentSlot slot) {
|
||||
super(player);
|
||||
this.original = original;
|
||||
this.hand = hand;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getOriginal() { return this.original; }
|
||||
public ItemStack getOriginal() {
|
||||
return this.original;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InteractionHand getHand() { return this.hand; }
|
||||
public EquipmentSlot getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,16 +37,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
* All subclasses are fired on {@link MinecraftForge#EVENT_BUS}.
|
||||
* See the individual documentation on each subevent for more details.
|
||||
**/
|
||||
public class PlayerInteractEvent extends PlayerEvent
|
||||
{
|
||||
public class PlayerInteractEvent extends PlayerEvent {
|
||||
private final InteractionHand hand;
|
||||
private final BlockPos pos;
|
||||
@Nullable
|
||||
private final Direction face;
|
||||
private InteractionResult cancellationResult = InteractionResult.PASS;
|
||||
|
||||
private PlayerInteractEvent(Player player, InteractionHand hand, BlockPos pos, @Nullable Direction face)
|
||||
{
|
||||
private PlayerInteractEvent(Player player, InteractionHand hand, BlockPos pos, @Nullable Direction face) {
|
||||
super(Preconditions.checkNotNull(player, "Null player in PlayerInteractEvent!"));
|
||||
this.hand = Preconditions.checkNotNull(hand, "Null hand in PlayerInteractEvent!");
|
||||
this.pos = Preconditions.checkNotNull(pos, "Null position in PlayerInteractEvent!");
|
||||
@@ -56,20 +54,18 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
/**
|
||||
* This event is fired on both sides whenever a player right clicks an entity.
|
||||
*
|
||||
* "Interact at" is an interact where the local vector (which part of the entity you clicked) is known.
|
||||
* "Specific" is an interact where the local vector (which part of the entity you clicked) is known.
|
||||
* The state of this event affects whether {@link Entity#interactAt(Player, Vec3, InteractionHand)} is called.
|
||||
*
|
||||
* Let result be the return value of {@link Entity#interactAt(Player, Vec3, InteractionHand)}, or {@link #cancellationResult} if the event is cancelled.
|
||||
* If we are on the client and result is not {@link InteractionResult#SUCCESS}, the client will then try {@link EntityInteract}.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class EntityInteractSpecific extends PlayerInteractEvent
|
||||
{
|
||||
public static class EntityInteractSpecific extends PlayerInteractEvent {
|
||||
private final Vec3 localPos;
|
||||
private final Entity target;
|
||||
|
||||
public EntityInteractSpecific(Player player, InteractionHand hand, Entity target, Vec3 localPos)
|
||||
{
|
||||
public EntityInteractSpecific(Player player, InteractionHand hand, Entity target, Vec3 localPos) {
|
||||
super(player, hand, target.blockPosition(), null);
|
||||
this.localPos = localPos;
|
||||
this.target = target;
|
||||
@@ -81,13 +77,11 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* [-width / 2, width / 2] while Y values will be in the range [0, height]
|
||||
* @return The local position
|
||||
*/
|
||||
public Vec3 getLocalPos()
|
||||
{
|
||||
public Vec3 getLocalPos() {
|
||||
return localPos;
|
||||
}
|
||||
|
||||
public Entity getTarget()
|
||||
{
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -106,18 +100,15 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* If we are on the client and result is not {@link InteractionResult#SUCCESS}, the client will then try {@link RightClickItem}.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class EntityInteract extends PlayerInteractEvent
|
||||
{
|
||||
public static class EntityInteract extends PlayerInteractEvent {
|
||||
private final Entity target;
|
||||
|
||||
public EntityInteract(Player player, InteractionHand hand, Entity target)
|
||||
{
|
||||
public EntityInteract(Player player, InteractionHand hand, Entity target) {
|
||||
super(player, hand, target.blockPosition(), null);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Entity getTarget()
|
||||
{
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -136,8 +127,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* Note that handling things differently on the client vs server may cause desynchronizations!
|
||||
*/
|
||||
@Cancelable
|
||||
public static class RightClickBlock extends PlayerInteractEvent
|
||||
{
|
||||
public static class RightClickBlock extends PlayerInteractEvent {
|
||||
private Result useBlock = Result.DEFAULT;
|
||||
private Result useItem = Result.DEFAULT;
|
||||
private BlockHitResult hitVec;
|
||||
@@ -150,24 +140,21 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
/**
|
||||
* @return If {@link Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)} should be called
|
||||
*/
|
||||
public Result getUseBlock()
|
||||
{
|
||||
public Result getUseBlock() {
|
||||
return useBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If {@link Item#onItemUseFirst} and {@link Item#useOn(UseOnContext)} should be called
|
||||
*/
|
||||
public Result getUseItem()
|
||||
{
|
||||
public Result getUseItem() {
|
||||
return useItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The ray trace result targeting the block.
|
||||
*/
|
||||
public BlockHitResult getHitVec()
|
||||
{
|
||||
public BlockHitResult getHitVec() {
|
||||
return hitVec;
|
||||
}
|
||||
|
||||
@@ -177,8 +164,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* Note that default activation can be blocked if the user is sneaking and holding an item that does not return true to {@link Item#doesSneakBypassUse}. <br>
|
||||
* ALLOW: {@link Block#updateOrDestroy(BlockState, BlockState, LevelAccessor, BlockPos, int, int)} will always be called, unless {@link Item#onItemUseFirst} does not pass. <br>
|
||||
*/
|
||||
public void setUseBlock(Result triggerBlock)
|
||||
{
|
||||
public void setUseBlock(Result triggerBlock) {
|
||||
this.useBlock = triggerBlock;
|
||||
}
|
||||
|
||||
@@ -187,17 +173,14 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* DEFAULT: {@link Item#onItemUseFirst} will always be called, and {@link Item#useOn(UseOnContext)} will be called if the block passes. <br>
|
||||
* ALLOW: {@link Item#onItemUseFirst} will always be called, and {@link Item#useOn(UseOnContext)} will be called if the block passes, regardless of cooldowns or emptiness. <br>
|
||||
*/
|
||||
public void setUseItem(Result triggerItem)
|
||||
{
|
||||
public void setUseItem(Result triggerItem) {
|
||||
this.useItem = triggerItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanceled(boolean canceled)
|
||||
{
|
||||
public void setCanceled(boolean canceled) {
|
||||
super.setCanceled(canceled);
|
||||
if (canceled)
|
||||
{
|
||||
if (canceled) {
|
||||
useBlock = Result.DENY;
|
||||
useItem = Result.DENY;
|
||||
}
|
||||
@@ -212,10 +195,8 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* If we are on the client and result is not {@link InteractionResult#SUCCESS}, the client will then continue to other hands.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class RightClickItem extends PlayerInteractEvent
|
||||
{
|
||||
public RightClickItem(Player player, InteractionHand hand)
|
||||
{
|
||||
public static class RightClickItem extends PlayerInteractEvent {
|
||||
public RightClickItem(Player player, InteractionHand hand) {
|
||||
super(player, hand, player.blockPosition(), null);
|
||||
}
|
||||
}
|
||||
@@ -225,10 +206,8 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* The server is not aware of when the client right clicks empty space with an empty hand, you will need to tell the server yourself.
|
||||
* This event cannot be canceled.
|
||||
*/
|
||||
public static class RightClickEmpty extends PlayerInteractEvent
|
||||
{
|
||||
public RightClickEmpty(Player player, InteractionHand hand)
|
||||
{
|
||||
public static class RightClickEmpty extends PlayerInteractEvent {
|
||||
public RightClickEmpty(Player player, InteractionHand hand) {
|
||||
super(player, hand, player.blockPosition(), null);
|
||||
}
|
||||
}
|
||||
@@ -249,21 +228,13 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* Therefore, in creative mode, {@link #setUseBlock} and {@link #setUseItem} have no effect.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class LeftClickBlock extends PlayerInteractEvent
|
||||
{
|
||||
public static class LeftClickBlock extends PlayerInteractEvent {
|
||||
private Result useBlock = Result.DEFAULT;
|
||||
private Result useItem = Result.DEFAULT;
|
||||
private final Action action;
|
||||
|
||||
@Deprecated(since = "1.20.1", forRemoval = true)
|
||||
public LeftClickBlock(Player player, BlockPos pos, Direction face)
|
||||
{
|
||||
this(player, pos, face, Action.START);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public LeftClickBlock(Player player, BlockPos pos, Direction face, Action action)
|
||||
{
|
||||
public LeftClickBlock(Player player, BlockPos pos, Direction face, Action action) {
|
||||
super(player, InteractionHand.MAIN_HAND, pos, face);
|
||||
this.action = action;
|
||||
}
|
||||
@@ -271,16 +242,14 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
/**
|
||||
* @return If {@link Block#attack(BlockState, Level, BlockPos, Player)} should be called. Changing this has no effect in creative mode
|
||||
*/
|
||||
public Result getUseBlock()
|
||||
{
|
||||
public Result getUseBlock() {
|
||||
return useBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the block should be attempted to be mined with the current item. Changing this has no effect in creative mode
|
||||
*/
|
||||
public Result getUseItem()
|
||||
{
|
||||
public Result getUseItem() {
|
||||
return useItem;
|
||||
}
|
||||
|
||||
@@ -292,22 +261,18 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public void setUseBlock(Result triggerBlock)
|
||||
{
|
||||
public void setUseBlock(Result triggerBlock) {
|
||||
this.useBlock = triggerBlock;
|
||||
}
|
||||
|
||||
public void setUseItem(Result triggerItem)
|
||||
{
|
||||
public void setUseItem(Result triggerItem) {
|
||||
this.useItem = triggerItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanceled(boolean canceled)
|
||||
{
|
||||
public void setCanceled(boolean canceled) {
|
||||
super.setCanceled(canceled);
|
||||
if (canceled)
|
||||
{
|
||||
if (canceled) {
|
||||
useBlock = Result.DENY;
|
||||
useItem = Result.DENY;
|
||||
}
|
||||
@@ -334,10 +299,10 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
|
||||
public static Action convert(ServerboundPlayerActionPacket.Action action) {
|
||||
return switch (action) {
|
||||
default -> START;
|
||||
case START_DESTROY_BLOCK -> START;
|
||||
case STOP_DESTROY_BLOCK -> STOP;
|
||||
case ABORT_DESTROY_BLOCK -> ABORT;
|
||||
default -> START;
|
||||
case START_DESTROY_BLOCK -> START;
|
||||
case STOP_DESTROY_BLOCK -> STOP;
|
||||
case ABORT_DESTROY_BLOCK -> ABORT;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -348,10 +313,8 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* The server is not aware of when the client left clicks empty space, you will need to tell the server yourself.
|
||||
* This event cannot be canceled.
|
||||
*/
|
||||
public static class LeftClickEmpty extends PlayerInteractEvent
|
||||
{
|
||||
public LeftClickEmpty(Player player)
|
||||
{
|
||||
public static class LeftClickEmpty extends PlayerInteractEvent {
|
||||
public LeftClickEmpty(Player player) {
|
||||
super(player, InteractionHand.MAIN_HAND, player.blockPosition(), null);
|
||||
}
|
||||
}
|
||||
@@ -360,8 +323,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* @return The hand involved in this interaction. Will never be null.
|
||||
*/
|
||||
@NotNull
|
||||
public InteractionHand getHand()
|
||||
{
|
||||
public InteractionHand getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
@@ -369,8 +331,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* @return The itemstack involved in this interaction, {@code ItemStack.EMPTY} if the hand was empty.
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
public ItemStack getItemStack() {
|
||||
return getEntity().getItemInHand(hand);
|
||||
}
|
||||
|
||||
@@ -382,8 +343,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* @return The position involved in this interaction.
|
||||
*/
|
||||
@NotNull
|
||||
public BlockPos getPos()
|
||||
{
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -391,24 +351,21 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* @return The face involved in this interaction. For all non-block interactions, this will return null.
|
||||
*/
|
||||
@Nullable
|
||||
public Direction getFace()
|
||||
{
|
||||
public Direction getFace() {
|
||||
return face;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Convenience method to get the level of this interaction.
|
||||
*/
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return getEntity().level();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The effective, i.e. logical, side of this interaction. This will be {@link LogicalSide#CLIENT} on the client thread, and {@link LogicalSide#SERVER} on the server thread.
|
||||
*/
|
||||
public LogicalSide getSide()
|
||||
{
|
||||
public LogicalSide getSide() {
|
||||
return getLevel().isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER;
|
||||
}
|
||||
|
||||
@@ -417,8 +374,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* method of the event. By default, this is {@link InteractionResult#PASS}, meaning cancelled events will cause
|
||||
* the client to keep trying more interactions until something works.
|
||||
*/
|
||||
public InteractionResult getCancellationResult()
|
||||
{
|
||||
public InteractionResult getCancellationResult() {
|
||||
return cancellationResult;
|
||||
}
|
||||
|
||||
@@ -427,9 +383,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* method of the event.
|
||||
* Note that this only has an effect on {@link RightClickBlock}, {@link RightClickItem}, {@link EntityInteract}, and {@link EntityInteractSpecific}.
|
||||
*/
|
||||
public void setCancellationResult(InteractionResult result)
|
||||
{
|
||||
public void setCancellationResult(InteractionResult result) {
|
||||
this.cancellationResult = result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,12 +23,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @see PlayerSpawnPhantomsEvent#setResult for the effects of each result.
|
||||
*/
|
||||
@Event.HasResult
|
||||
public class PlayerSpawnPhantomsEvent extends PlayerEvent
|
||||
{
|
||||
public class PlayerSpawnPhantomsEvent extends PlayerEvent {
|
||||
private int phantomsToSpawn;
|
||||
|
||||
public PlayerSpawnPhantomsEvent(Player player, int phantomsToSpawn)
|
||||
{
|
||||
public PlayerSpawnPhantomsEvent(Player player, int phantomsToSpawn) {
|
||||
super(player);
|
||||
this.phantomsToSpawn = phantomsToSpawn;
|
||||
}
|
||||
@@ -36,8 +34,7 @@ public class PlayerSpawnPhantomsEvent extends PlayerEvent
|
||||
/**
|
||||
* @return How many phantoms will be spawned, if spawning is successful. The default value is randomly generated.
|
||||
*/
|
||||
public int getPhantomsToSpawn()
|
||||
{
|
||||
public int getPhantomsToSpawn() {
|
||||
return phantomsToSpawn;
|
||||
}
|
||||
|
||||
@@ -45,8 +42,7 @@ public class PlayerSpawnPhantomsEvent extends PlayerEvent
|
||||
* Sets the number of phantoms to be spawned.
|
||||
* @param phantomsToSpawn How many phantoms should spawn, given checks are passed.
|
||||
*/
|
||||
public void setPhantomsToSpawn(int phantomsToSpawn)
|
||||
{
|
||||
public void setPhantomsToSpawn(int phantomsToSpawn) {
|
||||
this.phantomsToSpawn = phantomsToSpawn;
|
||||
}
|
||||
|
||||
@@ -59,8 +55,7 @@ public class PlayerSpawnPhantomsEvent extends PlayerEvent
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
public void setResult(@NotNull Result result)
|
||||
{
|
||||
public void setResult(@NotNull Result result) {
|
||||
super.setResult(result);
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,8 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public class PlayerXpEvent extends PlayerEvent
|
||||
{
|
||||
|
||||
public PlayerXpEvent(Player player)
|
||||
{
|
||||
public class PlayerXpEvent extends PlayerEvent {
|
||||
public PlayerXpEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@@ -30,22 +27,17 @@ public class PlayerXpEvent extends PlayerEvent
|
||||
* It can be cancelled, and no further processing will be done.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class PickupXp extends PlayerXpEvent
|
||||
{
|
||||
|
||||
public static class PickupXp extends PlayerXpEvent {
|
||||
private final ExperienceOrb orb;
|
||||
|
||||
public PickupXp(Player player, ExperienceOrb orb)
|
||||
{
|
||||
public PickupXp(Player player, ExperienceOrb orb) {
|
||||
super(player);
|
||||
this.orb = orb;
|
||||
}
|
||||
|
||||
public ExperienceOrb getOrb()
|
||||
{
|
||||
public ExperienceOrb getOrb() {
|
||||
return orb;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,27 +45,21 @@ public class PlayerXpEvent extends PlayerEvent
|
||||
* It can be cancelled, and no further processing will be done.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class XpChange extends PlayerXpEvent
|
||||
{
|
||||
|
||||
public static class XpChange extends PlayerXpEvent {
|
||||
private int amount;
|
||||
|
||||
public XpChange(Player player, int amount)
|
||||
{
|
||||
public XpChange(Player player, int amount) {
|
||||
super(player);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public int getAmount()
|
||||
{
|
||||
public int getAmount() {
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount)
|
||||
{
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,27 +67,20 @@ public class PlayerXpEvent extends PlayerEvent
|
||||
* It can be cancelled, and no further processing will be done.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class LevelChange extends PlayerXpEvent
|
||||
{
|
||||
|
||||
public static class LevelChange extends PlayerXpEvent {
|
||||
private int levels;
|
||||
|
||||
public LevelChange(Player player, int levels)
|
||||
{
|
||||
public LevelChange(Player player, int levels) {
|
||||
super(player);
|
||||
this.levels = levels;
|
||||
}
|
||||
|
||||
public int getLevels()
|
||||
{
|
||||
public int getLevels() {
|
||||
return this.levels;
|
||||
}
|
||||
|
||||
public void setLevels(int levels)
|
||||
{
|
||||
public void setLevels(int levels) {
|
||||
this.levels = levels;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.block.BaseFireBlock;
|
||||
import net.minecraft.world.level.portal.PortalShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
@@ -20,7 +19,6 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
@@ -33,32 +31,28 @@ import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockEvent extends Event
|
||||
{
|
||||
public class BlockEvent extends Event {
|
||||
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
|
||||
|
||||
private final LevelAccessor level;
|
||||
private final BlockPos pos;
|
||||
private final BlockState state;
|
||||
public BlockEvent(LevelAccessor level, BlockPos pos, BlockState state)
|
||||
{
|
||||
|
||||
public BlockEvent(LevelAccessor level, BlockPos pos, BlockState state) {
|
||||
this.pos = pos;
|
||||
this.level = level;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public LevelAccessor getLevel()
|
||||
{
|
||||
public LevelAccessor getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public BlockPos getPos()
|
||||
{
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public BlockState getState()
|
||||
{
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -67,31 +61,25 @@ public class BlockEvent extends Event
|
||||
* Canceling this event will prevent the Block from being broken.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class BreakEvent extends BlockEvent
|
||||
{
|
||||
public static class BreakEvent extends BlockEvent {
|
||||
/** Reference to the Player who broke the block. If no player is available, use a EntityFakePlayer */
|
||||
private final Player player;
|
||||
private int exp;
|
||||
|
||||
public BreakEvent(Level level, BlockPos pos, BlockState state, Player player)
|
||||
{
|
||||
public BreakEvent(Level level, BlockPos pos, BlockState state, Player player) {
|
||||
super(level, pos, state);
|
||||
this.player = player;
|
||||
|
||||
if (state == null || !ForgeHooks.isCorrectToolForDrops(state, player)) // Handle empty block or player unable to break block scenario
|
||||
{
|
||||
if (state == null || !ForgeHooks.isCorrectToolForDrops(state, player)) { // Handle empty block or player unable to break block scenario
|
||||
this.exp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int fortuneLevel = player.getMainHandItem().getEnchantmentLevel(Enchantments.BLOCK_FORTUNE);
|
||||
} else {
|
||||
int fortuneLevel = player.getMainHandItem().getEnchantmentLevel(Enchantments.FORTUNE);
|
||||
int silkTouchLevel = player.getMainHandItem().getEnchantmentLevel(Enchantments.SILK_TOUCH);
|
||||
this.exp = state.getExpDrop(level, level.random, pos, fortuneLevel, silkTouchLevel);
|
||||
}
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -100,8 +88,7 @@ public class BlockEvent extends Event
|
||||
*
|
||||
* @return The experience to drop or 0 if the event was canceled
|
||||
*/
|
||||
public int getExpToDrop()
|
||||
{
|
||||
public int getExpToDrop() {
|
||||
return this.isCanceled() ? 0 : exp;
|
||||
}
|
||||
|
||||
@@ -110,8 +97,7 @@ public class BlockEvent extends Event
|
||||
*
|
||||
* @param exp 1 or higher to drop experience, else nothing will drop
|
||||
*/
|
||||
public void setExpToDrop(int exp)
|
||||
{
|
||||
public void setExpToDrop(int exp) {
|
||||
this.exp = exp;
|
||||
}
|
||||
}
|
||||
@@ -122,23 +108,20 @@ public class BlockEvent extends Event
|
||||
* If a Block Place event is cancelled, the block will not be placed.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class EntityPlaceEvent extends BlockEvent
|
||||
{
|
||||
public static class EntityPlaceEvent extends BlockEvent {
|
||||
private final Entity entity;
|
||||
private final BlockSnapshot blockSnapshot;
|
||||
private final BlockState placedBlock;
|
||||
private final BlockState placedAgainst;
|
||||
|
||||
public EntityPlaceEvent(@NotNull BlockSnapshot blockSnapshot, @NotNull BlockState placedAgainst, @Nullable Entity entity)
|
||||
{
|
||||
public EntityPlaceEvent(@NotNull BlockSnapshot blockSnapshot, @NotNull BlockState placedAgainst, @Nullable Entity entity) {
|
||||
super(blockSnapshot.getLevel(), blockSnapshot.getPos(), !(entity instanceof Player) ? blockSnapshot.getReplacedBlock() : blockSnapshot.getCurrentBlock());
|
||||
this.entity = entity;
|
||||
this.blockSnapshot = blockSnapshot;
|
||||
this.placedBlock = !(entity instanceof Player) ? blockSnapshot.getReplacedBlock() : blockSnapshot.getCurrentBlock();
|
||||
this.placedAgainst = placedAgainst;
|
||||
|
||||
if (DEBUG)
|
||||
{
|
||||
if (DEBUG) {
|
||||
System.out.printf("Created EntityPlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][Entity: %s ]\n", getPlacedBlock(), placedAgainst, entity);
|
||||
}
|
||||
}
|
||||
@@ -158,15 +141,13 @@ public class BlockEvent extends Event
|
||||
* block.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class EntityMultiPlaceEvent extends EntityPlaceEvent
|
||||
{
|
||||
public static class EntityMultiPlaceEvent extends EntityPlaceEvent {
|
||||
private final List<BlockSnapshot> blockSnapshots;
|
||||
|
||||
public EntityMultiPlaceEvent(@NotNull List<BlockSnapshot> blockSnapshots, @NotNull BlockState placedAgainst, @Nullable Entity entity) {
|
||||
super(blockSnapshots.get(0), placedAgainst, entity);
|
||||
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
|
||||
if (DEBUG)
|
||||
{
|
||||
if (DEBUG) {
|
||||
System.out.printf("Created EntityMultiPlaceEvent - [PlacedAgainst: %s ][Entity: %s ]\n", placedAgainst, entity);
|
||||
}
|
||||
}
|
||||
@@ -177,8 +158,7 @@ public class BlockEvent extends Event
|
||||
*
|
||||
* @return immutable list of replaced BlockSnapshots
|
||||
*/
|
||||
public List<BlockSnapshot> getReplacedBlockSnapshots()
|
||||
{
|
||||
public List<BlockSnapshot> getReplacedBlockSnapshots() {
|
||||
return blockSnapshots;
|
||||
}
|
||||
}
|
||||
@@ -189,13 +169,11 @@ public class BlockEvent extends Event
|
||||
* does. This event is only called on the server.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class NeighborNotifyEvent extends BlockEvent
|
||||
{
|
||||
public static class NeighborNotifyEvent extends BlockEvent {
|
||||
private final EnumSet<Direction> notifiedSides;
|
||||
private final boolean forceRedstoneUpdate;
|
||||
|
||||
public NeighborNotifyEvent(Level level, BlockPos pos, BlockState state, EnumSet<Direction> notifiedSides, boolean forceRedstoneUpdate)
|
||||
{
|
||||
public NeighborNotifyEvent(Level level, BlockPos pos, BlockState state, EnumSet<Direction> notifiedSides, boolean forceRedstoneUpdate) {
|
||||
super(level, pos, state);
|
||||
this.notifiedSides = notifiedSides;
|
||||
this.forceRedstoneUpdate = forceRedstoneUpdate;
|
||||
@@ -206,8 +184,7 @@ public class BlockEvent extends Event
|
||||
*
|
||||
* @return list of notified directions
|
||||
*/
|
||||
public EnumSet<Direction> getNotifiedSides()
|
||||
{
|
||||
public EnumSet<Direction> getNotifiedSides() {
|
||||
return notifiedSides;
|
||||
}
|
||||
|
||||
@@ -215,8 +192,7 @@ public class BlockEvent extends Event
|
||||
* Get if redstone update was forced during setBlock call (0x16 to flags)
|
||||
* @return if the flag was set
|
||||
*/
|
||||
public boolean getForceRedstoneUpdate()
|
||||
{
|
||||
public boolean getForceRedstoneUpdate() {
|
||||
return forceRedstoneUpdate;
|
||||
}
|
||||
}
|
||||
@@ -228,31 +204,26 @@ public class BlockEvent extends Event
|
||||
* even if the liquid usually does do that (like water).
|
||||
*/
|
||||
@HasResult
|
||||
public static class CreateFluidSourceEvent extends Event
|
||||
{
|
||||
public static class CreateFluidSourceEvent extends Event {
|
||||
private final Level level;
|
||||
private final BlockPos pos;
|
||||
private final BlockState state;
|
||||
|
||||
public CreateFluidSourceEvent(Level level, BlockPos pos, BlockState state)
|
||||
{
|
||||
public CreateFluidSourceEvent(Level level, BlockPos pos, BlockState state) {
|
||||
this.level = level;
|
||||
this.pos = pos;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public BlockPos getPos()
|
||||
{
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public BlockState getState()
|
||||
{
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -266,14 +237,12 @@ public class BlockEvent extends Event
|
||||
* {@link #getPos()} will return the position of the block to be changed.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class FluidPlaceBlockEvent extends BlockEvent
|
||||
{
|
||||
public static class FluidPlaceBlockEvent extends BlockEvent {
|
||||
private final BlockPos liquidPos;
|
||||
private BlockState newState;
|
||||
private BlockState origState;
|
||||
|
||||
public FluidPlaceBlockEvent(LevelAccessor level, BlockPos pos, BlockPos liquidPos, BlockState state)
|
||||
{
|
||||
public FluidPlaceBlockEvent(LevelAccessor level, BlockPos pos, BlockPos liquidPos, BlockState state) {
|
||||
super(level, pos, state);
|
||||
this.liquidPos = liquidPos;
|
||||
this.newState = state;
|
||||
@@ -283,29 +252,25 @@ public class BlockEvent extends Event
|
||||
/**
|
||||
* @return The position of the liquid this event originated from. This may be the same as {@link #getPos()}.
|
||||
*/
|
||||
public BlockPos getLiquidPos()
|
||||
{
|
||||
public BlockPos getLiquidPos() {
|
||||
return liquidPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The block state that will be placed after this event resolves.
|
||||
*/
|
||||
public BlockState getNewState()
|
||||
{
|
||||
public BlockState getNewState() {
|
||||
return newState;
|
||||
}
|
||||
|
||||
public void setNewState(BlockState state)
|
||||
{
|
||||
public void setNewState(BlockState state) {
|
||||
this.newState = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The state of the block to be changed before the event was fired.
|
||||
*/
|
||||
public BlockState getOriginalState()
|
||||
{
|
||||
public BlockState getOriginalState() {
|
||||
return origState;
|
||||
}
|
||||
}
|
||||
@@ -314,10 +279,8 @@ public class BlockEvent extends Event
|
||||
* Fired when a crop block grows. See subevents.
|
||||
*
|
||||
*/
|
||||
public static class CropGrowEvent extends BlockEvent
|
||||
{
|
||||
public CropGrowEvent(Level level, BlockPos pos, BlockState state)
|
||||
{
|
||||
public static class CropGrowEvent extends BlockEvent {
|
||||
public CropGrowEvent(Level level, BlockPos pos, BlockState state) {
|
||||
super(level, pos, state);
|
||||
}
|
||||
|
||||
@@ -333,10 +296,8 @@ public class BlockEvent extends Event
|
||||
* <br>
|
||||
*/
|
||||
@HasResult
|
||||
public static class Pre extends CropGrowEvent
|
||||
{
|
||||
public Pre(Level level, BlockPos pos, BlockState state)
|
||||
{
|
||||
public static class Pre extends CropGrowEvent {
|
||||
public Pre(Level level, BlockPos pos, BlockState state) {
|
||||
super(level, pos, state);
|
||||
}
|
||||
}
|
||||
@@ -350,17 +311,15 @@ public class BlockEvent extends Event
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
*/
|
||||
public static class Post extends CropGrowEvent
|
||||
{
|
||||
public static class Post extends CropGrowEvent {
|
||||
private final BlockState originalState;
|
||||
public Post(Level level, BlockPos pos, BlockState original, BlockState state)
|
||||
{
|
||||
|
||||
public Post(Level level, BlockPos pos, BlockState original, BlockState state) {
|
||||
super(level, pos, state);
|
||||
originalState = original;
|
||||
}
|
||||
|
||||
public BlockState getOriginalState()
|
||||
{
|
||||
public BlockState getOriginalState() {
|
||||
return originalState;
|
||||
}
|
||||
}
|
||||
@@ -371,14 +330,11 @@ public class BlockEvent extends Event
|
||||
* This event is {@link Cancelable}
|
||||
*/
|
||||
@Cancelable
|
||||
public static class FarmlandTrampleEvent extends BlockEvent
|
||||
{
|
||||
|
||||
public static class FarmlandTrampleEvent extends BlockEvent {
|
||||
private final Entity entity;
|
||||
private final float fallDistance;
|
||||
|
||||
public FarmlandTrampleEvent(Level level, BlockPos pos, BlockState state, float fallDistance, Entity entity)
|
||||
{
|
||||
public FarmlandTrampleEvent(Level level, BlockPos pos, BlockState state, float fallDistance, Entity entity) {
|
||||
super(level, pos, state);
|
||||
this.entity = entity;
|
||||
this.fallDistance = fallDistance;
|
||||
@@ -400,18 +356,15 @@ public class BlockEvent extends Event
|
||||
* If cancelled, the portal will not be spawned.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class PortalSpawnEvent extends BlockEvent
|
||||
{
|
||||
public static class PortalSpawnEvent extends BlockEvent {
|
||||
private final PortalShape size;
|
||||
|
||||
public PortalSpawnEvent(LevelAccessor level, BlockPos pos, BlockState state, PortalShape size)
|
||||
{
|
||||
public PortalSpawnEvent(LevelAccessor level, BlockPos pos, BlockState state, PortalShape size) {
|
||||
super(level, pos, state);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public PortalShape getPortalSize()
|
||||
{
|
||||
public PortalShape getPortalSize() {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
@@ -427,15 +380,13 @@ public class BlockEvent extends Event
|
||||
* from changing the block's state.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class BlockToolModificationEvent extends BlockEvent
|
||||
{
|
||||
public static class BlockToolModificationEvent extends BlockEvent {
|
||||
private final UseOnContext context;
|
||||
private final ToolAction toolAction;
|
||||
private final boolean simulate;
|
||||
private BlockState state;
|
||||
|
||||
public BlockToolModificationEvent(BlockState originalState, @NotNull UseOnContext context, ToolAction toolAction, boolean simulate)
|
||||
{
|
||||
public BlockToolModificationEvent(BlockState originalState, @NotNull UseOnContext context, ToolAction toolAction, boolean simulate) {
|
||||
super(context.getLevel(), context.getClickedPos(), originalState);
|
||||
this.context = context;
|
||||
this.state = originalState;
|
||||
@@ -448,24 +399,21 @@ public class BlockEvent extends Event
|
||||
* May be null based on what was provided by {@link #getContext() the use on context}.
|
||||
*/
|
||||
@Nullable
|
||||
public Player getPlayer()
|
||||
{
|
||||
public Player getPlayer() {
|
||||
return this.context.getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tool being used
|
||||
*/
|
||||
public ItemStack getHeldItemStack()
|
||||
{
|
||||
public ItemStack getHeldItemStack() {
|
||||
return this.context.getItemInHand();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the action being performed
|
||||
*/
|
||||
public ToolAction getToolAction()
|
||||
{
|
||||
public ToolAction getToolAction() {
|
||||
return this.toolAction;
|
||||
}
|
||||
|
||||
@@ -476,8 +424,7 @@ public class BlockEvent extends Event
|
||||
* @return {@code true} if this event should not perform any actions that modify the level.
|
||||
* If {@code false}, then level-modifying actions can be performed.
|
||||
*/
|
||||
public boolean isSimulated()
|
||||
{
|
||||
public boolean isSimulated() {
|
||||
return this.simulate;
|
||||
}
|
||||
|
||||
@@ -487,8 +434,7 @@ public class BlockEvent extends Event
|
||||
* @return the nonnull use on context that this event was performed in
|
||||
*/
|
||||
@NotNull
|
||||
public UseOnContext getContext()
|
||||
{
|
||||
public UseOnContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -498,8 +444,7 @@ public class BlockEvent extends Event
|
||||
* @param finalState the state to transform the block into after tool use
|
||||
* @see #getFinalState()
|
||||
*/
|
||||
public void setFinalState(@Nullable BlockState finalState)
|
||||
{
|
||||
public void setFinalState(@Nullable BlockState finalState) {
|
||||
this.state = finalState;
|
||||
}
|
||||
|
||||
@@ -510,8 +455,7 @@ public class BlockEvent extends Event
|
||||
*
|
||||
* @return the state to transform the block into after tool use
|
||||
*/
|
||||
public BlockState getFinalState()
|
||||
{
|
||||
public BlockState getFinalState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ 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.ChunkStatus;
|
||||
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.minecraftforge.common.MinecraftForge;
|
||||
@@ -55,14 +55,14 @@ public class ChunkDataEvent extends ChunkEvent {
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class Load extends ChunkDataEvent {
|
||||
private ChunkStatus.ChunkType status;
|
||||
private ChunkType status;
|
||||
|
||||
public Load(ChunkAccess chunk, CompoundTag data, ChunkStatus.ChunkType status) {
|
||||
public Load(ChunkAccess chunk, CompoundTag data, ChunkType status) {
|
||||
super(chunk, data);
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ChunkStatus.ChunkType getStatus() {
|
||||
public ChunkType getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.event.level;
|
||||
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
@@ -17,12 +17,10 @@ import com.google.common.base.Preconditions;
|
||||
* Base class for Noteblock Events
|
||||
*
|
||||
*/
|
||||
public class NoteBlockEvent extends BlockEvent
|
||||
{
|
||||
public class NoteBlockEvent extends BlockEvent {
|
||||
private int noteId;
|
||||
|
||||
protected NoteBlockEvent(Level world, BlockPos pos, BlockState state, int note)
|
||||
{
|
||||
protected NoteBlockEvent(Level world, BlockPos pos, BlockState state, int note) {
|
||||
super(world, pos, state);
|
||||
this.noteId = note;
|
||||
}
|
||||
@@ -31,8 +29,7 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* Get the Note the Noteblock is tuned to
|
||||
* @return the Note
|
||||
*/
|
||||
public Note getNote()
|
||||
{
|
||||
public Note getNote() {
|
||||
return Note.fromId(noteId);
|
||||
}
|
||||
|
||||
@@ -40,8 +37,7 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* Get the Octave of the note this Noteblock is tuned to
|
||||
* @return the Octave
|
||||
*/
|
||||
public Octave getOctave()
|
||||
{
|
||||
public Octave getOctave() {
|
||||
return Octave.fromId(noteId);
|
||||
}
|
||||
|
||||
@@ -49,8 +45,7 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* get the vanilla note-id, which contains information about both Note and Octave. Most modders should not need this.
|
||||
* @return an ID for the note
|
||||
*/
|
||||
public int getVanillaNoteId()
|
||||
{
|
||||
public int getVanillaNoteId() {
|
||||
return noteId;
|
||||
}
|
||||
|
||||
@@ -60,8 +55,7 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* @param note the Note
|
||||
* @param octave the Octave
|
||||
*/
|
||||
public void setNote(Note note, Octave octave)
|
||||
{
|
||||
public void setNote(Note note, Octave octave) {
|
||||
Preconditions.checkArgument(octave != Octave.HIGH || note == Note.F_SHARP, "Octave.HIGH is only valid for Note.F_SHARP!");
|
||||
this.noteId = note.ordinal() + octave.ordinal() * 12;
|
||||
}
|
||||
@@ -71,23 +65,19 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* Canceling this event will stop the note from playing.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Play extends NoteBlockEvent
|
||||
{
|
||||
public static class Play extends NoteBlockEvent {
|
||||
private NoteBlockInstrument instrument;
|
||||
|
||||
public Play(Level world, BlockPos pos, BlockState state, int note, NoteBlockInstrument instrument)
|
||||
{
|
||||
public Play(Level world, BlockPos pos, BlockState state, int note, NoteBlockInstrument instrument) {
|
||||
super(world, pos, state, note);
|
||||
this.instrument = instrument;
|
||||
}
|
||||
|
||||
public NoteBlockInstrument getInstrument()
|
||||
{
|
||||
public NoteBlockInstrument getInstrument() {
|
||||
return instrument;
|
||||
}
|
||||
|
||||
public void setInstrument(NoteBlockInstrument instrument)
|
||||
{
|
||||
public void setInstrument(NoteBlockInstrument instrument) {
|
||||
this.instrument = instrument;
|
||||
}
|
||||
}
|
||||
@@ -97,25 +87,21 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* Canceling this event will not change the note and also stop the Noteblock from playing it's note.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Change extends NoteBlockEvent
|
||||
{
|
||||
public static class Change extends NoteBlockEvent {
|
||||
private final Note oldNote;
|
||||
private final Octave oldOctave;
|
||||
|
||||
public Change(Level world, BlockPos pos, BlockState state, int oldNote, int newNote)
|
||||
{
|
||||
public Change(Level world, BlockPos pos, BlockState state, int oldNote, int newNote) {
|
||||
super(world, pos, state, newNote);
|
||||
this.oldNote = Note.fromId(oldNote);
|
||||
this.oldOctave = Octave.fromId(oldNote);
|
||||
}
|
||||
|
||||
public Note getOldNote()
|
||||
{
|
||||
public Note getOldNote() {
|
||||
return oldNote;
|
||||
}
|
||||
|
||||
public Octave getOldOctave()
|
||||
{
|
||||
public Octave getOldOctave() {
|
||||
return oldOctave;
|
||||
}
|
||||
}
|
||||
@@ -125,8 +111,7 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* For altered notes such as G-Sharp / A-Flat the Sharp variant is used here.
|
||||
*
|
||||
*/
|
||||
public static enum Note
|
||||
{
|
||||
public static enum Note {
|
||||
F_SHARP,
|
||||
G,
|
||||
G_SHARP,
|
||||
@@ -142,8 +127,7 @@ public class NoteBlockEvent extends BlockEvent
|
||||
|
||||
private static final Note[] values = values();
|
||||
|
||||
static Note fromId(int id)
|
||||
{
|
||||
static Note fromId(int id) {
|
||||
return values[id % 12];
|
||||
}
|
||||
}
|
||||
@@ -153,16 +137,13 @@ public class NoteBlockEvent extends BlockEvent
|
||||
* Together with {@link Note} it fully describes the note.
|
||||
*
|
||||
*/
|
||||
public static enum Octave
|
||||
{
|
||||
public static enum Octave {
|
||||
LOW,
|
||||
MID,
|
||||
HIGH; // only valid for F_SHARP
|
||||
|
||||
static Octave fromId(int id)
|
||||
{
|
||||
static Octave fromId(int id) {
|
||||
return id < 12 ? LOW : id == 24 ? HIGH : MID;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.world.entity.npc.VillagerData;
|
||||
import net.minecraft.world.entity.npc.VillagerProfession;
|
||||
import net.minecraft.world.entity.npc.VillagerTrades.ItemListing;
|
||||
import net.minecraftforge.common.BasicItemListing;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.event.server.ServerAboutToStartEvent;
|
||||
|
||||
@@ -8,7 +8,6 @@ package net.minecraftforge.event.village;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.world.entity.npc.VillagerTrades.ItemListing;
|
||||
import net.minecraftforge.common.BasicItemListing;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.event.server.ServerAboutToStartEvent;
|
||||
|
||||
Reference in new issue
Block a user