mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
New BiomeLoadingEvent that allows modders to edit biomes as they are being deserialized.
This commit is contained in:
1 parent
ce6c664acd
commit
11e3281b3f
10 files changed
+386
-1
No files matched your search
@@ -39,6 +39,8 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
@@ -104,9 +106,15 @@ import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeAmbience;
|
||||
import net.minecraft.world.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.biome.MobSpawnInfo;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifierManager;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
|
||||
import net.minecraftforge.common.world.MobSpawnInfoBuilder;
|
||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||
import net.minecraftforge.event.DifficultyChangeEvent;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
@@ -130,6 +138,7 @@ import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
import net.minecraftforge.event.entity.player.CriticalHitEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.BiomeLoadingEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.NoteBlockEvent;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
@@ -839,6 +848,21 @@ public class ForgeHooks
|
||||
throw new RuntimeException("Mod fluids must override createAttributes.");
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BiomeCallbackFunction
|
||||
{
|
||||
Biome apply(final Biome.Climate climate, final Biome.Category category, final Float depth, final Float scale, final BiomeAmbience effects, final BiomeGenerationSettings gen, final MobSpawnInfo spawns);
|
||||
}
|
||||
|
||||
public static Biome enhanceBiome(final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final Float depth, final Float scale, final BiomeAmbience effects, final BiomeGenerationSettings gen, final MobSpawnInfo spawns, final RecordCodecBuilder.Instance<Biome> codec, final BiomeCallbackFunction callback)
|
||||
{
|
||||
BiomeGenerationSettingsBuilder genBuilder = new BiomeGenerationSettingsBuilder(gen);
|
||||
MobSpawnInfoBuilder spawnBuilder = new MobSpawnInfoBuilder(spawns);
|
||||
BiomeLoadingEvent event = new BiomeLoadingEvent(name, climate, category, depth, scale, effects, genBuilder, spawnBuilder);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return callback.apply(event.getClimate(), event.getCategory(), event.getDepth(), event.getScale(), event.getEffects(), event.getGeneration().func_242508_a(), event.getSpawns().func_242577_b());
|
||||
}
|
||||
|
||||
private static class LootTableContext
|
||||
{
|
||||
public final ResourceLocation name;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2020.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.world;
|
||||
|
||||
import net.minecraft.world.biome.BiomeGenerationSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BiomeGenerationSettingsBuilder extends BiomeGenerationSettings.Builder
|
||||
{
|
||||
public BiomeGenerationSettingsBuilder(BiomeGenerationSettings orig)
|
||||
{
|
||||
field_242504_a = Optional.of(orig.func_242500_d());
|
||||
orig.getCarvingStages().forEach(k -> field_242505_b.put(k, orig.func_242489_a(k)));
|
||||
orig.func_242498_c().forEach(l -> field_242506_c.add(new ArrayList<>(l)));
|
||||
field_242507_d.addAll(orig.func_242487_a());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2020.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.world;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.world.biome.MobSpawnInfo;
|
||||
|
||||
public class MobSpawnInfoBuilder extends MobSpawnInfo.Builder
|
||||
{
|
||||
private final Set<EntityClassification> typesView = Collections.unmodifiableSet(this.field_242567_a.keySet());
|
||||
private final Set<EntityType<?>> costView = Collections.unmodifiableSet(this.field_242568_b.keySet());
|
||||
|
||||
public MobSpawnInfoBuilder(MobSpawnInfo orig)
|
||||
{
|
||||
orig.getSpawnerTypes().forEach(k -> {
|
||||
field_242567_a.get(k).clear();
|
||||
field_242567_a.get(k).addAll(new java.util.ArrayList<>(orig.func_242559_a(k)));
|
||||
});
|
||||
orig.getEntityTypes().forEach(k -> field_242568_b.put(k, orig.func_242558_a(k)));
|
||||
field_242569_c = orig.func_242557_a();
|
||||
field_242570_d = orig.func_242562_b();
|
||||
}
|
||||
|
||||
public Set<EntityClassification> getSpawnerTypes()
|
||||
{
|
||||
return this.typesView;
|
||||
}
|
||||
|
||||
public List<MobSpawnInfo.Spawners> getSpawner(EntityClassification type)
|
||||
{
|
||||
return this.field_242567_a.get(type);
|
||||
}
|
||||
|
||||
public Set<EntityType<?>> getEntityTypes()
|
||||
{
|
||||
return this.costView;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MobSpawnInfo.SpawnCosts getCost(EntityType<?> type)
|
||||
{
|
||||
return this.field_242568_b.get(type);
|
||||
}
|
||||
|
||||
public float getProbability()
|
||||
{
|
||||
return this.field_242569_c;
|
||||
}
|
||||
|
||||
public MobSpawnInfoBuilder disablePlayerSpawn()
|
||||
{
|
||||
this.field_242570_d = false;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2020.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.world;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeAmbience;
|
||||
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
|
||||
import net.minecraftforge.common.world.MobSpawnInfoBuilder;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
|
||||
/**
|
||||
* This event fires when a Biome is created from json or when a registered biome is re-created for worldgen.
|
||||
* It allows mods to edit a biome (like add a mob spawn) before it gets used for worldgen.
|
||||
*
|
||||
* In order to maintain the most compatibility possible with other mods' modifications to a biome,
|
||||
* the event should be assigned a {@link net.minecraftforge.eventbus.api.EventPriority} as follows:
|
||||
*
|
||||
* - Additions to any list/map contained in a biome : {@link EventPriority#HIGH}
|
||||
* - Removals to any list/map contained in a biome : {@link EventPriority#NORMAL}
|
||||
* - Any other modification : {@link EventPriority#LOW}
|
||||
*
|
||||
* Be aware that another mod could have done an operation beforehand, so an expected value out of a vanilla biome might not
|
||||
* always be the same, depending on other mods.
|
||||
*/
|
||||
public class BiomeLoadingEvent extends Event
|
||||
{
|
||||
private final ResourceLocation name;
|
||||
private Biome.Climate climate;
|
||||
private Biome.Category category;
|
||||
private float depth;
|
||||
private float scale;
|
||||
private BiomeAmbience effects;
|
||||
private final BiomeGenerationSettingsBuilder gen;
|
||||
private final MobSpawnInfoBuilder spawns;
|
||||
|
||||
public BiomeLoadingEvent(final ResourceLocation name, final Biome.Climate climate, final Biome.Category category, final float depth, final float scale, final BiomeAmbience effects, final BiomeGenerationSettingsBuilder gen, final MobSpawnInfoBuilder spawns)
|
||||
{
|
||||
this.name = name;
|
||||
this.climate = climate;
|
||||
this.category = category;
|
||||
this.depth = depth;
|
||||
this.scale = scale;
|
||||
this.effects = effects;
|
||||
this.gen = gen;
|
||||
this.spawns = spawns;
|
||||
}
|
||||
|
||||
public ResourceLocation getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public Biome.Climate getClimate()
|
||||
{
|
||||
return climate;
|
||||
}
|
||||
|
||||
public void setClimate(final Biome.Climate value)
|
||||
{
|
||||
this.climate = value;
|
||||
}
|
||||
|
||||
public Biome.Category getCategory()
|
||||
{
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(final Biome.Category value)
|
||||
{
|
||||
this.category = value;
|
||||
}
|
||||
|
||||
public float getDepth()
|
||||
{
|
||||
return depth;
|
||||
}
|
||||
|
||||
public void setDepth(final float value)
|
||||
{
|
||||
this.depth = value;
|
||||
}
|
||||
|
||||
public float getScale()
|
||||
{
|
||||
return scale;
|
||||
}
|
||||
|
||||
public void setScale(final float value)
|
||||
{
|
||||
this.scale = value;
|
||||
}
|
||||
|
||||
public BiomeAmbience getEffects()
|
||||
{
|
||||
return effects;
|
||||
}
|
||||
|
||||
public void setEffects(final BiomeAmbience value)
|
||||
{
|
||||
this.effects = value;
|
||||
}
|
||||
|
||||
public BiomeGenerationSettingsBuilder getGeneration()
|
||||
{
|
||||
return gen;
|
||||
}
|
||||
|
||||
public MobSpawnInfoBuilder getSpawns()
|
||||
{
|
||||
return spawns;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user