Start migration

This commit is contained in:
Aleksey 2021-04-08 21:55:07 +03:00
parent 6630ce0cab
commit 47ed597358
491 changed files with 12045 additions and 11953 deletions

View file

@ -16,13 +16,13 @@ import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.world.item.ItemStack;
import net.minecraft.screen.AnvilScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.interfaces.AnvilScreenHandlerExtended;
@Mixin(AnvilScreen.class)
@ -30,12 +30,12 @@ public class AnvilScreenMixin extends ForgingScreen<AnvilScreenHandler> {
@Shadow
private TextFieldWidget nameField;
private final List<AbstractButtonWidget> be_buttons = Lists.newArrayList();
private AnvilScreenHandlerExtended anvilHandler;
public AnvilScreenMixin(AnvilScreenHandler handler, PlayerInventory playerInventory, Text title,
Identifier texture) {
ResourceLocation texture) {
super(handler, playerInventory, title, texture);
}
@ -43,19 +43,19 @@ public class AnvilScreenMixin extends ForgingScreen<AnvilScreenHandler> {
protected void be_setup(CallbackInfo info) {
this.be_buttons.clear();
int x = (width - backgroundWidth) / 2;
int y = (height - backgroundHeight) / 2;
this.anvilHandler = (AnvilScreenHandlerExtended) this.handler;
this.be_buttons.add(new ButtonWidget(x + 8, y + 45, 15, 20, new LiteralText("<"), (b) -> be_previousRecipe()));
int y = (height - backgroundHeight) / 2;
this.anvilHandler = (AnvilScreenHandlerExtended) this.handler;
this.be_buttons.add(new ButtonWidget(x + 8, y + 45, 15, 20, new LiteralText("<"), (b) -> be_previousRecipe()));
this.be_buttons.add(new ButtonWidget(x + 154, y + 45, 15, 20, new LiteralText(">"), (b) -> be_nextRecipe()));
}
@Inject(method = "renderForeground", at = @At("TAIL"))
protected void be_renderForeground(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
this.be_buttons.forEach(button -> {
button.render(matrices, mouseX, mouseY, delta);
});
}
@Inject(method = "onSlotUpdate", at = @At("HEAD"), cancellable = true)
public void be_onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack, CallbackInfo info) {
AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler;
@ -71,15 +71,15 @@ public class AnvilScreenMixin extends ForgingScreen<AnvilScreenHandler> {
this.be_buttons.forEach(button -> button.visible = false);
}
}
private void be_nextRecipe() {
this.anvilHandler.be_nextRecipe();
}
private void be_previousRecipe() {
this.anvilHandler.be_previousRecipe();
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (client != null) {

View file

@ -11,15 +11,15 @@ import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.client.render.Camera;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.effect.StatusEffectInstance;
import net.minecraft.world.entity.effect.StatusEffects;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Category;
import ru.betterend.client.ClientOptions;
@ -33,23 +33,25 @@ public class BackgroundRendererMixin {
private static float fogDensity;
private static float lerp;
private static long time;
@Shadow
private static float red;
@Shadow
private static float green;
@Shadow
private static float blue;
@Inject(method = "render", at = @At("RETURN"))
private static void be_onRender(Camera camera, float tickDelta, ClientWorld world, int i, float f, CallbackInfo info) {
private static void be_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f,
CallbackInfo info) {
long l = Util.getMeasuringTimeMs() - time;
time += l;
lerp += l * 0.001F;
if (lerp > 1) lerp = 1;
if (lerp > 1)
lerp = 1;
FluidState fluidState = camera.getSubmergedFluidState();
if (fluidState.isEmpty() && world.getRegistryKey().equals(World.END)) {
if (fluidState.isEmpty() && world.dimension().equals(Level.END)) {
Entity entity = camera.getFocusedEntity();
boolean skip = false;
if (entity instanceof LivingEntity) {
@ -62,20 +64,21 @@ public class BackgroundRendererMixin {
blue *= 4;
}
}
BackgroundInfo.red = red;
BackgroundInfo.green = green;
BackgroundInfo.blue = blue;
}
@Inject(method = "applyFog", at = @At("HEAD"), cancellable = true)
private static void be_fogDensity(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, boolean thickFog, CallbackInfo info) {
private static void be_fogDensity(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance,
boolean thickFog, CallbackInfo info) {
Entity entity = camera.getFocusedEntity();
Biome biome = entity.world.getBiome(entity.getBlockPos());
FluidState fluidState = camera.getSubmergedFluidState();
if (ClientOptions.useFogDensity() && biome.getCategory() == Category.THEEND && fluidState.isEmpty()) {
EndBiome endBiome = EndBiomes.getRenderBiome(biome);
if (fogDensity == 0) {
fogDensity = endBiome.getFogDensity();
lastFogDensity = fogDensity;
@ -85,12 +88,12 @@ public class BackgroundRendererMixin {
fogDensity = endBiome.getFogDensity();
lerp = 0;
}
float fog = MathHelper.lerp(lerp, lastFogDensity, fogDensity);
float fog = Mth.lerp(lerp, lastFogDensity, fogDensity);
BackgroundInfo.fog = fog;
float start = viewDistance * 0.75F / fog;
float end = viewDistance / fog;
if (entity instanceof LivingEntity) {
LivingEntity le = (LivingEntity) entity;
StatusEffectInstance effect = le.getStatusEffect(StatusEffects.BLINDNESS);
@ -100,19 +103,17 @@ public class BackgroundRendererMixin {
start = 0;
end *= 0.03F;
BackgroundInfo.blindness = 1;
}
else {
} else {
float delta = (float) duration / 20F;
BackgroundInfo.blindness = delta;
start = MathHelper.lerp(delta, start, 0);
end = MathHelper.lerp(delta, end, end * 0.03F);
start = Mth.lerp(delta, start, 0);
end = Mth.lerp(delta, end, end * 0.03F);
}
}
else {
} else {
BackgroundInfo.blindness = 0;
}
}
RenderSystem.fogStart(start);
RenderSystem.fogEnd(end);
RenderSystem.fogMode(GlStateManager.FogMode.LINEAR);

View file

@ -10,9 +10,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.BlockRenderView;
import ru.betterend.client.ClientOptions;
import ru.betterend.registry.EndBlocks;
@ -25,17 +25,17 @@ public class BiomeColorsMixin {
private static final int STREAM_COLOR = MHelper.color(105, 213, 244);
private static final Point[] OFFSETS;
private static final boolean HAS_SODIUM;
@Inject(method = "getWaterColor", at = @At("RETURN"), cancellable = true)
private static void be_getWaterColor(BlockRenderView world, BlockPos pos, CallbackInfoReturnable<Integer> info) {
if (ClientOptions.useSulfurWaterColor()) {
BlockRenderView view = HAS_SODIUM ? MinecraftClient.getInstance().world : world;
Mutable mut = new Mutable();
MutableBlockPos mut = new MutableBlockPos();
mut.setY(pos.getY());
for (int i = 0; i < OFFSETS.length; i++) {
mut.setX(pos.getX() + OFFSETS[i].x);
mut.setZ(pos.getZ() + OFFSETS[i].y);
if ((view.getBlockState(mut).isOf(EndBlocks.BRIMSTONE))) {
if ((view.getBlockState(mut).is(EndBlocks.BRIMSTONE))) {
info.setReturnValue(i < 16 ? STREAM_COLOR : POISON_COLOR);
info.cancel();
return;
@ -43,10 +43,10 @@ public class BiomeColorsMixin {
}
}
}
static {
HAS_SODIUM = FabricLoader.getInstance().isModLoaded("sodium");
OFFSETS = new Point[20];
for (int i = 0; i < 3; i++) {
int p = i - 1;
@ -55,7 +55,7 @@ public class BiomeColorsMixin {
OFFSETS[i + 6] = new Point(-2, p);
OFFSETS[i + 9] = new Point(2, p);
}
for (int i = 0; i < 4; i++) {
int inner = i + 16;
Direction dir = BlocksHelper.HORIZONTAL[i];

View file

@ -6,23 +6,22 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.NetworkThreadUtils;
import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket;
import ru.betterend.blocks.entities.ESignBlockEntity;
import ru.betterend.client.gui.BlockSignEditScreen;
@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin
{
public class ClientPlayNetworkHandlerMixin {
@Shadow
private MinecraftClient client;
@Shadow
private ClientWorld world;
private ClientLevel world;
@Inject(method = "onSignEditorOpen", at = @At(value = "HEAD"), cancellable = true)
public void be_openSignEditor(SignEditorOpenS2CPacket packet, CallbackInfo info) {

View file

@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.client.recipebook.ClientRecipeBook;
import net.minecraft.client.recipebook.RecipeBookGroup;
import net.minecraft.recipe.Recipe;
import net.minecraft.world.item.crafting.Recipe;
import ru.betterend.interfaces.BetterEndRecipe;
import ru.betterend.recipe.builders.AlloyingRecipe;

View file

@ -7,22 +7,22 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.EnchantingTableBlock;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.EnchantingTableBlock;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import ru.betterend.registry.EndTags;
@Mixin(EnchantingTableBlock.class)
public abstract class EnchantingTableBlockMixin extends Block {
public EnchantingTableBlockMixin(Settings settings) {
public EnchantingTableBlockMixin(Properties settings) {
super(settings);
}
@Inject(method = "randomDisplayTick", at = @At(value = "TAIL"))
private void be_onRandomDisplayTick(BlockState state, World world, BlockPos pos, Random random, CallbackInfo info) {
@Inject(method = "animateTick", at = @At(value = "TAIL"))
private void be_onRandomDisplayTick(BlockState state, Level world, BlockPos pos, Random random, CallbackInfo info) {
for (int px = -2; px <= 2; ++px) {
for (int pz = -2; pz <= 2; ++pz) {
if (px > -2 && px < 2 && pz == -1) {
@ -30,12 +30,14 @@ public abstract class EnchantingTableBlockMixin extends Block {
}
if (random.nextInt(16) == 0) {
for (int py = 0; py <= 1; ++py) {
BlockPos blockPos = pos.add(px, py, pz);
BlockPos blockPos = pos.offset(px, py, pz);
if (world.getBlockState(blockPos).isIn(EndTags.BOOKSHELVES)) {
if (!world.isAir(pos.add(px / 2, 0, pz / 2))) {
if (!world.isAir(pos.offset(px / 2, 0, pz / 2))) {
break;
}
world.addParticle(ParticleTypes.ENCHANT, pos.getX() + 0.5, pos.getY() + 2.0, pos.getZ() + 0.5, px + random.nextFloat() - 0.5, py - random.nextFloat() - 1.0, pz + random.nextFloat() - 0.5);
world.addParticle(ParticleTypes.ENCHANT, pos.getX() + 0.5, pos.getY() + 2.0,
pos.getZ() + 0.5, px + random.nextFloat() - 0.5, py - random.nextFloat() - 1.0,
pz + random.nextFloat() - 0.5);
}
}
}

View file

@ -17,10 +17,10 @@ import net.minecraft.client.gui.screen.CreditsScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.sound.MusicType;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.sound.MusicSound;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.core.Registry;
import net.minecraft.world.level.Level;
import ru.betterend.interfaces.IColorProvider;
import ru.betterend.util.MHelper;
@ -28,17 +28,17 @@ import ru.betterend.util.MHelper;
public class MinecraftClientMixin {
@Shadow
public ClientPlayerEntity player;
@Shadow
public Screen currentScreen;
@Shadow
@Final
public InGameHud inGameHud;
@Shadow
public ClientWorld world;
public ClientLevel world;
@Shadow
@Final
private BlockColors blockColors;
@ -46,27 +46,28 @@ public class MinecraftClientMixin {
@Shadow
@Final
private ItemColors itemColors;
@Inject(method = "<init>*", at = @At("TAIL"))
private void be_onInit(RunArgs args, CallbackInfo info) {
Registry.BLOCK.forEach(block -> {
if (block instanceof IColorProvider) {
IColorProvider provider = (IColorProvider) block;
blockColors.registerColorProvider(provider.getProvider(), block);
blockColors.registerColorProvider(provider.getBlockProvider(), block);
itemColors.register(provider.getItemProvider(), block.asItem());
}
});
}
@Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true)
private void be_getEndMusic(CallbackInfoReturnable<MusicSound> info) {
if (!(this.currentScreen instanceof CreditsScreen) && this.player != null) {
if (this.player.world.getRegistryKey() == World.END) {
if (this.inGameHud.getBossBarHud().shouldPlayDragonMusic() && MHelper.lengthSqr(this.player.getX(), this.player.getZ()) < 250000) {
if (this.player.world.dimension() == Level.END) {
if (this.inGameHud.getBossBarHud().shouldPlayDragonMusic()
&& MHelper.lengthSqr(this.player.getX(), this.player.getZ()) < 250000) {
info.setReturnValue(MusicType.DRAGON);
}
else {
MusicSound sound = (MusicSound) this.world.getBiomeAccess().method_27344(this.player.getBlockPos()).getMusic().orElse(MusicType.END);
} else {
MusicSound sound = (MusicSound) this.world.getBiomeAccess().method_27344(this.player.getBlockPos())
.getMusic().orElse(MusicType.END);
info.setReturnValue(sound);
}
info.cancel();

View file

@ -13,14 +13,14 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.block.Block;
import net.minecraft.world.level.block.Block;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.item.Item;
import net.minecraft.world.item.Item;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import ru.betterend.BetterEnd;
import ru.betterend.patterns.Patterned;
import ru.betterend.world.generator.GeneratorOptions;
@ -30,11 +30,11 @@ public class ModelLoaderMixin {
@Final
@Shadow
private ResourceManager resourceManager;
@Inject(method = "loadModelFromJson", at = @At("HEAD"), cancellable = true)
private void be_loadModelPattern(Identifier id, CallbackInfoReturnable<JsonUnbakedModel> info) {
private void be_loadModelPattern(ResourceLocation id, CallbackInfoReturnable<JsonUnbakedModel> info) {
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
Identifier modelId = new Identifier(id.getNamespace(), "models/" + id.getPath() + ".json");
ResourceLocation modelId = new ResourceLocation(id.getNamespace(), "models/" + id.getPath() + ".json");
JsonUnbakedModel model;
try (Resource resource = this.resourceManager.getResource(modelId)) {
Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8);
@ -44,7 +44,7 @@ public class ModelLoaderMixin {
} catch (Exception ex) {
String data[] = id.getPath().split("/");
if (data.length > 1) {
Identifier itemId = new Identifier(id.getNamespace(), data[1]);
ResourceLocation itemId = new ResourceLocation(id.getNamespace(), data[1]);
Optional<Block> block = Registry.BLOCK.getOrEmpty(itemId);
if (block.isPresent()) {
if (block.get() instanceof Patterned) {
@ -64,8 +64,8 @@ public class ModelLoaderMixin {
}
}
}
private JsonUnbakedModel be_getModel(String data[], Identifier id, Patterned patterned) {
private JsonUnbakedModel be_getModel(String data[], ResourceLocation id, Patterned patterned) {
String pattern;
if (id.getPath().contains("item")) {
pattern = patterned.getModelPattern(id.getPath());
@ -78,14 +78,16 @@ public class ModelLoaderMixin {
}
JsonUnbakedModel model = JsonUnbakedModel.deserialize(pattern);
model.id = id.toString();
return model;
}
@ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE"))
public Identifier be_SwitchModel(Identifier id) {
if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft") && id.getPath().startsWith("blockstates/") && id.getPath().contains("chorus") && !id.getPath().contains("custom_")) {
id = new Identifier(id.getPath().replace("chorus", "custom_chorus"));
public ResourceLocation be_SwitchModel(ResourceLocation id) {
if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft")
&& id.getPath().startsWith("blockstates/") && id.getPath().contains("chorus")
&& !id.getPath().contains("custom_")) {
id = new ResourceLocation(id.getPath().replace("chorus", "custom_chorus"));
}
return id;
}

View file

@ -10,17 +10,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.google.gson.Gson;
import net.minecraft.block.Block;
import net.minecraft.world.level.block.Block;
import net.minecraft.client.render.model.json.ModelVariantMap;
import net.minecraft.util.JsonHelper;
import ru.betterend.patterns.BlockPatterned;
@Mixin(ModelVariantMap.class)
public abstract class ModelVariantMapMixin {
@Inject(method = "deserialize", at = @At("HEAD"), cancellable = true)
private static void be_deserializeBlockState(ModelVariantMap.DeserializationContext context, Reader reader, CallbackInfoReturnable<ModelVariantMap> info) {
Block block = context.getStateFactory().getDefaultState().getBlock();
private static void be_deserializeBlockState(ModelVariantMap.DeserializationContext context, Reader reader,
CallbackInfoReturnable<ModelVariantMap> info) {
Block block = context.getStateFactory().defaultBlockState().getBlock();
if (block instanceof BlockPatterned) {
String pattern = ((BlockPatterned) block).getStatesPattern(reader);
Gson gson = ContextGsonAccessor.class.cast(context).getGson();

View file

@ -14,8 +14,8 @@ import net.minecraft.client.sound.AbstractSoundInstance;
import net.minecraft.client.sound.MusicTracker;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.sound.MusicSound;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import ru.betterend.client.ClientOptions;
@Mixin(MusicTracker.class)
@ -23,21 +23,21 @@ public class MusicTrackerMixin {
@Shadow
@Final
private MinecraftClient client;
@Shadow
@Final
private Random random;
@Shadow
private SoundInstance current;
@Shadow
private int timeUntilNextSong;
private static float volume = 1;
private static float srcVolume = 0;
private static long time;
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
public void be_onTick(CallbackInfo info) {
if (ClientOptions.blendBiomeMusic()) {
@ -67,32 +67,33 @@ public class MusicTrackerMixin {
time = 0;
srcVolume = -1;
this.client.getSoundManager().stop(this.current);
this.timeUntilNextSong = MathHelper.nextInt(this.random, 0, musicSound.getMinDelay() / 2);
this.timeUntilNextSong = Mth.nextInt(this.random, 0, musicSound.getMinDelay() / 2);
this.current = null;
}
if (this.current == null && this.timeUntilNextSong-- <= 0) {
this.play(musicSound);
}
info.cancel();
}
else {
} else {
volume = 1;
}
}
}
private boolean be_isInEnd() {
return client.world != null && client.world.getRegistryKey().equals(World.END);
return client.world != null && client.world.dimension().equals(Level.END);
}
private boolean be_shouldChangeSound(MusicSound musicSound) {
return current != null && !musicSound.getSound().getId().equals(this.current.getId()) && musicSound.shouldReplaceCurrentMusic();
return current != null && !musicSound.getSound().getId().equals(this.current.getId())
&& musicSound.shouldReplaceCurrentMusic();
}
private boolean be_checkNullSound(MusicSound musicSound) {
return musicSound != null && musicSound.getSound() != null;
}
@Shadow
public void play(MusicSound type) {}
public void play(MusicSound type) {
}
}

View file

@ -11,32 +11,29 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.world.level.block.Block;
import net.minecraft.resource.NamespaceResourceManager;
import net.minecraft.resource.Resource;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import ru.betterend.BetterEnd;
import ru.betterend.patterns.BlockPatterned;
@Mixin(NamespaceResourceManager.class)
public abstract class NamespaceResourceManagerMixin {
@Shadow
public abstract Resource getResource(Identifier id);
@Inject(method = "getAllResources", cancellable = true, at = @At(
value = "NEW",
target = "java/io/FileNotFoundException",
shift = Shift.BEFORE))
public void be_getStatesPattern(Identifier id, CallbackInfoReturnable<List<Resource>> info) {
public abstract Resource getResource(ResourceLocation id);
@Inject(method = "getAllResources", cancellable = true, at = @At(value = "NEW", target = "java/io/FileNotFoundException", shift = Shift.BEFORE))
public void be_getStatesPattern(ResourceLocation id, CallbackInfoReturnable<List<Resource>> info) {
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
String[] data = id.getPath().split("/");
if (data.length > 1) {
Identifier blockId = BetterEnd.makeID(data[1].replace(".json", ""));
ResourceLocation blockId = BetterEnd.makeID(data[1].replace(".json", ""));
Block block = Registry.BLOCK.get(blockId);
if (block instanceof BlockPatterned) {
Identifier stateId = ((BlockPatterned) block).statePatternId();
ResourceLocation stateId = ((BlockPatterned) block).statePatternId();
try {
List<Resource> resources = Lists.newArrayList();
Resource stateRes = this.getResource(stateId);

View file

@ -26,8 +26,8 @@ import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.Identifier;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.Quaternion;
import ru.betterend.BetterEnd;
import ru.betterend.client.ClientOptions;
@ -36,12 +36,12 @@ import ru.betterend.util.MHelper;
@Mixin(WorldRenderer.class)
public class WorldRendererMixin {
private static final Identifier NEBULA_1 = BetterEnd.makeID("textures/sky/nebula_2.png");
private static final Identifier NEBULA_2 = BetterEnd.makeID("textures/sky/nebula_3.png");
private static final Identifier HORIZON = BetterEnd.makeID("textures/sky/nebula_1.png");
private static final Identifier STARS = BetterEnd.makeID("textures/sky/stars.png");
private static final Identifier FOG = BetterEnd.makeID("textures/sky/fog.png");
private static final ResourceLocation NEBULA_1 = BetterEnd.makeID("textures/sky/nebula_2.png");
private static final ResourceLocation NEBULA_2 = BetterEnd.makeID("textures/sky/nebula_3.png");
private static final ResourceLocation HORIZON = BetterEnd.makeID("textures/sky/nebula_1.png");
private static final ResourceLocation STARS = BetterEnd.makeID("textures/sky/stars.png");
private static final ResourceLocation FOG = BetterEnd.makeID("textures/sky/fog.png");
private static VertexBuffer stars1;
private static VertexBuffer stars2;
private static VertexBuffer stars3;
@ -60,21 +60,21 @@ public class WorldRendererMixin {
private static float blind02;
private static float blind06;
private static boolean directOpenGL = false;
@Shadow
@Final
private MinecraftClient client;
@Shadow
@Final
private TextureManager textureManager;
@Shadow
private ClientWorld world;
private ClientLevel world;
@Shadow
private int ticks;
@Inject(method = "<init>*", at = @At("TAIL"))
private void be_onInit(MinecraftClient client, BufferBuilderStorage bufferBuilders, CallbackInfo info) {
be_initStars();
@ -87,103 +87,106 @@ public class WorldRendererMixin {
axis2.normalize();
axis3.normalize();
axis4.normalize();
directOpenGL = FabricLoader.getInstance().isModLoaded("optifabric") || FabricLoader.getInstance().isModLoaded("immersive_portals");
directOpenGL = FabricLoader.getInstance().isModLoaded("optifabric")
|| FabricLoader.getInstance().isModLoaded("immersive_portals");
}
@Inject(method = "renderSky", at = @At("HEAD"), cancellable = true)
private void be_renderBetterEndSky(MatrixStack matrices, float tickDelta, CallbackInfo info) {
if (ClientOptions.isCustomSky() && client.world.getSkyProperties().getSkyType() == SkyProperties.SkyType.END) {
time = (ticks % 360000) * 0.000017453292F;
time2 = time * 2;
time3 = time * 3;
BackgroundRenderer.setFogBlack();
RenderSystem.enableTexture();
if (directOpenGL) {
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(516, 0.0F);
GL11.glEnable(GL11.GL_BLEND);
RenderSystem.depthMask(false);
}
else {
} else {
RenderSystem.enableAlphaTest();
RenderSystem.alphaFunc(516, 0.0F);
RenderSystem.enableBlend();
}
float blindA = 1F - BackgroundInfo.blindness;
blind02 = blindA * 0.2F;
blind06 = blindA * 0.6F;
if (blindA > 0) {
matrices.push();
matrices.multiply(new Quaternion(0, time, 0, false));
textureManager.bindTexture(HORIZON);
be_renderBuffer(matrices, horizon, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.7F * blindA);
matrices.pop();
matrices.push();
matrices.multiply(new Quaternion(0, -time, 0, false));
textureManager.bindTexture(NEBULA_1);
be_renderBuffer(matrices, nebulas1, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, blind02);
matrices.pop();
matrices.push();
matrices.multiply(new Quaternion(0, time2, 0, false));
textureManager.bindTexture(NEBULA_2);
be_renderBuffer(matrices, nebulas2, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, blind02);
matrices.pop();
textureManager.bindTexture(STARS);
matrices.push();
matrices.multiply(axis3.getRadialQuaternion(time));
be_renderBuffer(matrices, stars3, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, blind06);
matrices.pop();
matrices.push();
matrices.multiply(axis4.getRadialQuaternion(time2));
be_renderBuffer(matrices, stars4, VertexFormats.POSITION_TEXTURE, 1F, 1F, 1F, blind06);
matrices.pop();
}
float a = (BackgroundInfo.fog - 1F);
if (a > 0) {
if (a > 1) a = 1;
if (a > 1)
a = 1;
textureManager.bindTexture(FOG);
be_renderBuffer(matrices, fog, VertexFormats.POSITION_TEXTURE, BackgroundInfo.red, BackgroundInfo.green, BackgroundInfo.blue, a);
be_renderBuffer(matrices, fog, VertexFormats.POSITION_TEXTURE, BackgroundInfo.red, BackgroundInfo.green,
BackgroundInfo.blue, a);
}
RenderSystem.disableTexture();
if (blindA > 0) {
matrices.push();
matrices.multiply(axis1.getRadialQuaternion(time3));
be_renderBuffer(matrices, stars1, VertexFormats.POSITION, 1, 1, 1, blind06);
matrices.pop();
matrices.push();
matrices.multiply(axis2.getRadialQuaternion(time2));
be_renderBuffer(matrices, stars2, VertexFormats.POSITION, 0.95F, 0.64F, 0.93F, blind06);
matrices.pop();
}
RenderSystem.enableTexture();
RenderSystem.depthMask(true);
info.cancel();
}
}
private void be_renderBuffer(MatrixStack matrices, VertexBuffer buffer, VertexFormat format, float r, float g, float b, float a) {
private void be_renderBuffer(MatrixStack matrices, VertexBuffer buffer, VertexFormat format, float r, float g,
float b, float a) {
RenderSystem.color4f(r, g, b, a);
buffer.bind();
format.startDrawing(0L);
buffer.draw(matrices.peek().getModel(), 7);
VertexBuffer.unbind();
format.endDrawing();
buffer.draw(matrices.peek().getModel(), 7);
VertexBuffer.unbind();
format.endDrawing();
}
private void be_initStars() {
@ -197,8 +200,9 @@ public class WorldRendererMixin {
horizon = be_buildBufferHorizon(buffer, horizon);
fog = be_buildBufferFog(buffer, fog);
}
private VertexBuffer be_buildBufferStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) {
private VertexBuffer be_buildBufferStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize,
double maxSize, int count, long seed) {
if (buffer != null) {
buffer.close();
}
@ -210,8 +214,9 @@ public class WorldRendererMixin {
return buffer;
}
private VertexBuffer be_buildBufferUVStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) {
private VertexBuffer be_buildBufferUVStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize,
double maxSize, int count, long seed) {
if (buffer != null) {
buffer.close();
}
@ -223,8 +228,9 @@ public class WorldRendererMixin {
return buffer;
}
private VertexBuffer be_buildBufferFarFog(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) {
private VertexBuffer be_buildBufferFarFog(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize,
double maxSize, int count, long seed) {
if (buffer != null) {
buffer.close();
}
@ -236,7 +242,7 @@ public class WorldRendererMixin {
return buffer;
}
private VertexBuffer be_buildBufferHorizon(BufferBuilder bufferBuilder, VertexBuffer buffer) {
if (buffer != null) {
buffer.close();
@ -249,7 +255,7 @@ public class WorldRendererMixin {
return buffer;
}
private VertexBuffer be_buildBufferFog(BufferBuilder bufferBuilder, VertexBuffer buffer) {
if (buffer != null) {
buffer.close();
@ -262,7 +268,7 @@ public class WorldRendererMixin {
return buffer;
}
private void be_makeStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) {
Random random = new Random(seed);
buffer.begin(7, VertexFormats.POSITION);
@ -305,7 +311,7 @@ public class WorldRendererMixin {
}
}
}
private void be_makeUVStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) {
Random random = new Random(seed);
buffer.begin(7, VertexFormats.POSITION_TEXTURE);
@ -347,13 +353,13 @@ public class WorldRendererMixin {
double ah = ab * n + ae * o;
float texU = (pos >> 1) & 1;
float texV = (((pos + 1) >> 1) & 1) / 4F + minV;
pos ++;
pos++;
buffer.vertex(j + af, k + ad, l + ah).texture(texU, texV).next();
}
}
}
}
private void be_makeFarFog(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) {
Random random = new Random(seed);
buffer.begin(7, VertexFormats.POSITION_TEXTURE);
@ -398,26 +404,26 @@ public class WorldRendererMixin {
double ah = ab * n + ae * o;
float texU = (pos >> 1) & 1;
float texV = ((pos + 1) >> 1) & 1;
pos ++;
pos++;
buffer.vertex(j + af, k + ad, l + ah).texture(texU, texV).next();
}
}
}
}
private void be_makeCylinder(BufferBuilder buffer, int segments, double height, double radius) {
buffer.begin(7, VertexFormats.POSITION_TEXTURE);
for (int i = 0; i < segments; i ++) {
for (int i = 0; i < segments; i++) {
double a1 = (double) i * Math.PI * 2.0 / (double) segments;
double a2 = (double) (i + 1) * Math.PI * 2.0 / (double) segments;
double px1 = Math.sin(a1) * radius;
double pz1 = Math.cos(a1) * radius;
double px2 = Math.sin(a2) * radius;
double pz2 = Math.cos(a2) * radius;
float u0 = (float) i / (float) segments;
float u1 = (float) (i + 1) / (float) segments;
buffer.vertex(px1, -height, pz1).texture(u0, 0).next();
buffer.vertex(px1, height, pz1).texture(u0, 1).next();
buffer.vertex(px2, height, pz2).texture(u1, 1).next();