mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 00:07:45 +00:00
AlterGroundEvent for modifying block placement performed by AlterGroundDecorator (#9637)
This commit is contained in:
1 parent
2f229c5bb1
commit
2c965fac90
5 files changed
+128
No files matched your search
+11
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/world/level/levelgen/feature/treedecorators/AlterGroundDecorator.java
|
||||
+++ b/net/minecraft/world/level/levelgen/feature/treedecorators/AlterGroundDecorator.java
|
||||
@@ -72,7 +_,7 @@
|
||||
for(int i = 2; i >= -3; --i) {
|
||||
BlockPos blockpos = p_225975_.m_6630_(i);
|
||||
if (Feature.m_65788_(p_225974_.m_226058_(), blockpos)) {
|
||||
- p_225974_.m_226061_(blockpos, this.f_69303_.m_213972_(p_225974_.m_226067_(), p_225975_));
|
||||
+ p_225974_.m_226061_(blockpos, net.minecraftforge.event.ForgeEventFactory.alterGround(p_225974_.m_226058_(), p_225974_.m_226067_(), blockpos, this.f_69303_.m_213972_(p_225974_.m_226067_(), p_225975_)));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ 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.level.LevelSimulatedReader;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
@@ -128,6 +129,7 @@ import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
|
||||
import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent;
|
||||
import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent;
|
||||
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
|
||||
import net.minecraftforge.event.level.AlterGroundEvent;
|
||||
import net.minecraftforge.event.level.BlockEvent;
|
||||
import net.minecraftforge.event.level.BlockEvent.BlockToolModificationEvent;
|
||||
import net.minecraftforge.event.level.BlockEvent.CreateFluidSourceEvent;
|
||||
@@ -737,6 +739,13 @@ public class ForgeEventFactory
|
||||
return event;
|
||||
}
|
||||
|
||||
public static BlockState alterGround(LevelSimulatedReader level, RandomSource random, BlockPos pos, BlockState altered)
|
||||
{
|
||||
AlterGroundEvent event = new AlterGroundEvent(level, random, pos, altered);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getNewAlteredState();
|
||||
}
|
||||
|
||||
public static void fireChunkTicketLevelUpdated(ServerLevel level, long chunkPos, int oldTicketLevel, int newTicketLevel, @Nullable ChunkHolder chunkHolder)
|
||||
{
|
||||
if (oldTicketLevel != newTicketLevel)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.level;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.LevelSimulatedReader;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecorator;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* This event is fired when {@link net.minecraft.world.level.levelgen.feature.treedecorators.AlterGroundDecorator#placeBlockAt(TreeDecorator.Context, BlockPos)}
|
||||
* attempts to alter a ground block when generating a feature. An example of this would be large spruce trees converting grass blocks into podzol.
|
||||
* <p>
|
||||
* This event is not {@linkplain Cancelable cancellable}.
|
||||
* <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}.
|
||||
*/
|
||||
public class AlterGroundEvent extends Event {
|
||||
private final LevelSimulatedReader level;
|
||||
private final RandomSource random;
|
||||
private final BlockPos pos;
|
||||
private final BlockState originalAltered;
|
||||
private BlockState newAltered;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public AlterGroundEvent(LevelSimulatedReader level, RandomSource random, BlockPos pos, BlockState altered) {
|
||||
super();
|
||||
this.level = level;
|
||||
this.random = random;
|
||||
this.pos = pos;
|
||||
this.originalAltered = altered;
|
||||
this.newAltered = altered;
|
||||
}
|
||||
|
||||
public LevelSimulatedReader getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public RandomSource getRandom() {
|
||||
return this.random;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the position of the block that will be altered}
|
||||
*/
|
||||
public BlockPos getPos() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original block state that would be placed by the ground decorator}
|
||||
*/
|
||||
public BlockState getOriginalAlteredState() {
|
||||
return this.originalAltered;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the new block state to be placed by the ground decorator}
|
||||
*/
|
||||
public BlockState getNewAlteredState() {
|
||||
return this.newAltered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newAltered the new block state to be placed by the ground decorator
|
||||
*/
|
||||
public void setNewAlteredState(BlockState newAltered) {
|
||||
this.newAltered = newAltered;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.event.level.AlterGroundEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod("alter_ground_event_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class AlterGroundEventTest {
|
||||
public static final boolean ENABLE = true;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAlterGround(AlterGroundEvent event)
|
||||
{
|
||||
if (ENABLE) {
|
||||
if (event.getOriginalAlteredState().is(Blocks.PODZOL)) {
|
||||
event.setNewAlteredState(Blocks.REDSTONE_BLOCK.defaultBlockState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,5 +295,7 @@ modId="trade_with_villager_event_test"
|
||||
modId="chunk_event_load_new_chunk_test"
|
||||
[[mods]]
|
||||
modId="custom_fluid_container_test"
|
||||
[[mods]]
|
||||
modId="alter_ground_event_test"
|
||||
|
||||
# ADD ABOVE THIS LINE
|
||||
Reference in new issue
Block a user