Compiles, can get ingame, uses Mixins to work around missing Fork Hooks for structures and custom dimensions.

This commit is contained in:
Sebastian Hartte
2020-07-28 02:05:24 +02:00
parent 84e6aaa122
commit e640918ca0
14 changed files with 170 additions and 91 deletions
@@ -0,0 +1,36 @@
package appeng.mixins;
import appeng.worldgen.meteorite.MeteoriteStructure;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.gen.feature.structure.Structure;
import net.minecraft.world.gen.settings.DimensionStructuresSettings;
import net.minecraft.world.gen.settings.StructureSeparationSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* This Mixin will add the structure placement configuration for the meteorite structure
* to the static final immutable map that contains them. There is currently no
* Forge hook for this, and registering them during the registry event is already too late.
* <p>
* If this is not done, Meteorites spawn every chunk, since that is the default for missing entries.
*/
@Mixin(DimensionStructuresSettings.class)
public class DimensionStructuresSettingsMixin {
@Shadow
@Mutable
private static ImmutableMap<Structure<?>, StructureSeparationSettings> field_236191_b_;
@Inject(method = "<clinit>", at = @At("TAIL"))
private static void addMeteoriteSpreadConfig(CallbackInfo ci) {
field_236191_b_ = ImmutableMap.<Structure<?>, StructureSeparationSettings>builder()
.putAll(field_236191_b_)
.put(MeteoriteStructure.INSTANCE, new StructureSeparationSettings(32, 8, 124895654)).build();
}
}
@@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.OptionalLong;
@Mixin(DimensionType.class)
@Mixin(value = DimensionType.class)
public class DimensionTypeMixin {
@Inject(method = "func_236027_a_", at = @At("TAIL"))
@@ -14,7 +14,7 @@ import java.util.Optional;
@Mixin(DimensionRenderInfo.class)
public class SkyPropertiesMixin {
@Inject(method = "func_239215_a_", at = @At("HEAD"), cancellable = true, remap = false)
@Inject(method = "func_239215_a_", at = @At("HEAD"), cancellable = true)
private static void byDimensionType(Optional<RegistryKey<DimensionType>> optional,
CallbackInfoReturnable<DimensionRenderInfo> ci) {
if (optional.orElse(null) == SpatialDimensionManager.STORAGE_DIMENSION_TYPE) {
@@ -11,16 +11,16 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(WorldRenderer.class)
@Mixin(value = WorldRenderer.class)
public class SkyRenderMixin {
@Shadow(aliases = {"mc"})
private Minecraft client;
@Shadow
private Minecraft mc;
@SuppressWarnings("ConstantConditions")
@Inject(method = "renderSky", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderSky(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V", at = @At("HEAD"), cancellable = true)
public void renderSky(MatrixStack matrices, float tickDelta, CallbackInfo ci) {
if (client.world.func_234922_V_() == SpatialDimensionManager.STORAGE_DIMENSION_TYPE) {
if (mc.world.func_234922_V_() == SpatialDimensionManager.STORAGE_DIMENSION_TYPE) {
SpatialSkyRender.getInstance().render(matrices);
ci.cancel();
}
@@ -0,0 +1,16 @@
package appeng.mixins;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.structure.Structure;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(Structure.class)
public interface StructureAccessor {
@Invoker("func_236394_a_")
static <F extends Structure<?>> F register(String id, F feature, GenerationStage.Decoration defaultStage) {
throw new AssertionError();
}
}
@@ -1,20 +0,0 @@
package appeng.mixins;
import net.minecraft.block.TNTBlock;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import javax.annotation.Nullable;
@Mixin(TNTBlock.class)
public interface TntAccessor {
@Invoker
static void callPrimeTnt(World world, BlockPos pos, @Nullable LivingEntity igniter) {
throw new AssertionError("Mixin dummy");
}
}