[1.19.x] Added event for growing fungus (#8981)

This commit is contained in:
Jais Djurhuus-Kempel authored and GitHub committed 2022-09-08 16:11:59 +01:00
1 parent 0978a94358
commit 1c31f42dae
9 files changed
+106 -22

No files matched your search

@@ -17,6 +17,7 @@ import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.core.Holder;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ReloadableServerResources;
import net.minecraft.server.level.ChunkHolder;
@@ -29,6 +30,7 @@ import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.world.level.biome.MobSpawnSettings;
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;
@@ -613,11 +615,17 @@ public class ForgeEventFactory
return result == Result.DEFAULT ? level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) : result == Result.ALLOW;
}
@Deprecated(forRemoval = true, since = "1.19.2")
public static boolean saplingGrowTree(LevelAccessor level, RandomSource randomSource, BlockPos pos)
{
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(level, randomSource, pos);
return !blockGrowFeature(level, randomSource, pos, null).getResult().equals(Result.DENY);
}
public static SaplingGrowTreeEvent blockGrowFeature(LevelAccessor level, RandomSource randomSource, BlockPos pos, Holder<? extends ConfiguredFeature<?, ?>> holder)
{
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(level, randomSource, pos, holder);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult() != Result.DENY;
return event;
}
public static void fireChunkTicketLevelUpdated(ServerLevel level, long chunkPos, int oldTicketLevel, int newTicketLevel, @Nullable ChunkHolder chunkHolder)
@@ -6,38 +6,58 @@
package net.minecraftforge.event.level;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event.HasResult;
/**
* This event is fired whenever a sapling grows into a tree.
* This event is fired whenever a sapling, fungus, mushroom or azalea grows into a tree.
* This event is fired during sapling growth in
* {@link SaplingBlock#advanceTree(ServerLevel, BlockPos, BlockState, RandomSource)}.
* <p>
* This event is not {@linkplain Cancelable cancellable} but does {@linkplain HasResult have a result}.
* {@linkplain Result#ALLOW ALLOW} and {@linkplain Result#DEFAULT DEFAULT} will allow the sapling to grow.
* {@linkplain Result#ALLOW ALLOW} and {@linkplain Result#DEFAULT DEFAULT} will allow the sapling to grow
* using the features set on the event.
* {@linkplain Result#DENY DENY} will prevent the sapling from growing.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain net.minecraftforge.fml.LogicalSide#SERVER logical server}.
* TODO 1.20 rename event
*/
@HasResult
public class SaplingGrowTreeEvent extends LevelEvent
{
private final BlockPos pos;
private final RandomSource randomSource;
private final BlockPos pos;
private Holder<? extends ConfiguredFeature<?, ?>> feature;
@Deprecated(forRemoval = true, since = "1.19.2")
public SaplingGrowTreeEvent(LevelAccessor level, RandomSource randomSource, BlockPos pos)
{
this(level, randomSource, pos, null);
}
public SaplingGrowTreeEvent(LevelAccessor level, RandomSource randomSource, BlockPos pos, Holder<? extends ConfiguredFeature<?, ?>> feature)
{
super(level);
this.randomSource = randomSource;
this.pos = pos;
this.feature = feature;
}
/**
* {@return the random source which initiated the sapling growth}
*/
public RandomSource getRandomSource()
{
return this.randomSource;
}
/**
@@ -49,10 +69,13 @@ public class SaplingGrowTreeEvent extends LevelEvent
}
/**
* {@return the random source which initiated the sapling growth}
* {@return the holder of the feature which will be placed}
*/
public RandomSource getRandomSource()
{
return this.randomSource;
public Holder<? extends ConfiguredFeature<?, ?>> getFeature() {
return feature;
}
public void setFeature(Holder<? extends ConfiguredFeature<?, ?>> feature) {
this.feature = feature;
}
}