Continue mapping migration
This commit is contained in:
parent
99ade39404
commit
f03fd03bd0
499 changed files with 12567 additions and 12723 deletions
|
@ -1,10 +1,9 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import net.minecraft.client.sound.AbstractSoundInstance;
|
||||
|
||||
@Mixin(AbstractSoundInstance.class)
|
||||
public interface AbstractSoundInstanceAccessor {
|
||||
@Accessor("volume")
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.screens.inventory.AnvilScreen;
|
||||
import net.minecraft.client.gui.screens.inventory.ItemCombinerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.AnvilMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
@ -9,32 +20,19 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.client.gui.screen.ingame.AnvilScreen;
|
||||
import net.minecraft.client.gui.screen.ingame.ForgingScreen;
|
||||
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.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.resources.ResourceLocation;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import ru.betterend.interfaces.AnvilScreenHandlerExtended;
|
||||
|
||||
@Mixin(AnvilScreen.class)
|
||||
public class AnvilScreenMixin extends ForgingScreen<AnvilScreenHandler> {
|
||||
public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
|
||||
|
||||
@Shadow
|
||||
private TextFieldWidget nameField;
|
||||
|
||||
private final List<AbstractButtonWidget> be_buttons = Lists.newArrayList();
|
||||
private EditBox nameField;
|
||||
|
||||
private final List<AbstractWidget> be_buttons = Lists.newArrayList();
|
||||
private AnvilScreenHandlerExtended anvilHandler;
|
||||
|
||||
public AnvilScreenMixin(AnvilScreenHandler handler, PlayerInventory playerInventory, Text title,
|
||||
|
||||
public AnvilScreenMixin(AnvilMenu handler, Inventory playerInventory, Component title,
|
||||
ResourceLocation texture) {
|
||||
super(handler, playerInventory, title, texture);
|
||||
}
|
||||
|
@ -42,22 +40,22 @@ public class AnvilScreenMixin extends ForgingScreen<AnvilScreenHandler> {
|
|||
@Inject(method = "setup", at = @At("TAIL"))
|
||||
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()));
|
||||
this.be_buttons.add(new ButtonWidget(x + 154, y + 45, 15, 20, new LiteralText(">"), (b) -> be_nextRecipe()));
|
||||
int x = (width - imageWidth) / 2;
|
||||
int y = (height - imageHeight) / 2;
|
||||
this.anvilHandler = (AnvilScreenHandlerExtended) this.menu;
|
||||
this.be_buttons.add(new Button(x + 8, y + 45, 15, 20, new TextComponent("<"), (b) -> be_previousRecipe()));
|
||||
this.be_buttons.add(new Button(x + 154, y + 45, 15, 20, new TextComponent(">"), (b) -> be_nextRecipe()));
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "renderForeground", at = @At("TAIL"))
|
||||
protected void be_renderForeground(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
|
||||
protected void be_renderForeground(PoseStack 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) {
|
||||
public void be_onSlotUpdate(AbstractContainerMenu handler, int slotId, ItemStack stack, CallbackInfo info) {
|
||||
AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler;
|
||||
if (anvilHandler.be_getCurrentRecipe() != null) {
|
||||
if (anvilHandler.be_getRecipes().size() > 1) {
|
||||
|
@ -65,29 +63,29 @@ public class AnvilScreenMixin extends ForgingScreen<AnvilScreenHandler> {
|
|||
} else {
|
||||
this.be_buttons.forEach(button -> button.visible = false);
|
||||
}
|
||||
this.nameField.setText("");
|
||||
this.nameField.setValue("");
|
||||
info.cancel();
|
||||
} else {
|
||||
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) {
|
||||
for (AbstractButtonWidget elem : be_buttons) {
|
||||
if (minecraft != null) {
|
||||
for (AbstractWidget elem : be_buttons) {
|
||||
if (elem.visible && elem.mouseClicked(mouseX, mouseY, button)) {
|
||||
if (client.interactionManager != null) {
|
||||
if (minecraft.gameMode != null) {
|
||||
int i = be_buttons.indexOf(elem);
|
||||
this.client.interactionManager.clickButton(handler.syncId, i);
|
||||
this.minecraft.gameMode.handleInventoryButtonClick(menu.containerId, i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,54 +8,51 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.render.BackgroundRenderer;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.Category;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeCategory;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import ru.betterend.client.ClientOptions;
|
||||
import ru.betterend.registry.EndBiomes;
|
||||
import ru.betterend.util.BackgroundInfo;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
@Mixin(BackgroundRenderer.class)
|
||||
@Mixin(FogRenderer.class)
|
||||
public class BackgroundRendererMixin {
|
||||
private static float lastFogDensity;
|
||||
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, ClientLevel world, int i, float f,
|
||||
CallbackInfo info) {
|
||||
long l = Util.getMeasuringTimeMs() - time;
|
||||
private static void be_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f, CallbackInfo info) {
|
||||
long l = Util.getMillis() - time;
|
||||
time += l;
|
||||
lerp += l * 0.001F;
|
||||
if (lerp > 1)
|
||||
lerp = 1;
|
||||
|
||||
FluidState fluidState = camera.getSubmergedFluidState();
|
||||
if (lerp > 1) lerp = 1;
|
||||
|
||||
FluidState fluidState = camera.getFluidInCamera();
|
||||
if (fluidState.isEmpty() && world.dimension().equals(Level.END)) {
|
||||
Entity entity = camera.getFocusedEntity();
|
||||
Entity entity = camera.getEntity();
|
||||
boolean skip = false;
|
||||
if (entity instanceof LivingEntity) {
|
||||
MobEffectInstance effect = ((LivingEntity) entity).getMobEffect(MobEffects.NIGHT_VISION);
|
||||
MobEffectInstance effect = ((LivingEntity) entity).getEffect(MobEffects.NIGHT_VISION);
|
||||
skip = effect != null && effect.getDuration() > 0;
|
||||
}
|
||||
if (!skip) {
|
||||
|
@ -64,21 +61,20 @@ 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) {
|
||||
Entity entity = camera.getFocusedEntity();
|
||||
Biome biome = entity.world.getBiome(entity.getBlockPos());
|
||||
FluidState fluidState = camera.getSubmergedFluidState();
|
||||
if (ClientOptions.useFogDensity() && biome.getCategory() == Category.THEEND && fluidState.isEmpty()) {
|
||||
private static void be_fogDensity(Camera camera, FogRenderer.FogMode fogType, float viewDistance, boolean thickFog, CallbackInfo info) {
|
||||
Entity entity = camera.getEntity();
|
||||
Biome biome = entity.level.getBiome(entity.blockPosition());
|
||||
FluidState fluidState = camera.getFluidInCamera();
|
||||
if (ClientOptions.useFogDensity() && biome.getBiomeCategory() == BiomeCategory.THEEND && fluidState.isEmpty()) {
|
||||
EndBiome endBiome = EndBiomes.getRenderBiome(biome);
|
||||
|
||||
|
||||
if (fogDensity == 0) {
|
||||
fogDensity = endBiome.getFogDensity();
|
||||
lastFogDensity = fogDensity;
|
||||
|
@ -88,32 +84,34 @@ public class BackgroundRendererMixin {
|
|||
fogDensity = endBiome.getFogDensity();
|
||||
lerp = 0;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
MobEffectInstance effect = le.getMobEffect(MobEffects.BLINDNESS);
|
||||
MobEffectInstance effect = le.getEffect(MobEffects.BLINDNESS);
|
||||
if (effect != null) {
|
||||
int duration = effect.getDuration();
|
||||
if (duration > 20) {
|
||||
start = 0;
|
||||
end *= 0.03F;
|
||||
BackgroundInfo.blindness = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
float delta = (float) duration / 20F;
|
||||
BackgroundInfo.blindness = delta;
|
||||
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);
|
||||
|
|
|
@ -9,11 +9,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.world.BiomeColors;
|
||||
import net.minecraft.client.renderer.BiomeColors;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import ru.betterend.client.ClientOptions;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
@ -25,11 +25,11 @@ 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) {
|
||||
private static void be_getWaterColor(BlockAndTintGetter world, BlockPos pos, CallbackInfoReturnable<Integer> info) {
|
||||
if (ClientOptions.useSulfurWaterColor()) {
|
||||
BlockRenderView view = HAS_SODIUM ? Minecraft.getInstance().world : world;
|
||||
BlockAndTintGetter view = HAS_SODIUM ? Minecraft.getInstance().level : world;
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
mut.setY(pos.getY());
|
||||
for (int i = 0; i < OFFSETS.length; i++) {
|
||||
|
@ -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,13 +55,13 @@ 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];
|
||||
OFFSETS[inner] = new Point(dir.getOffsetX(), dir.getOffsetZ());
|
||||
OFFSETS[inner] = new Point(dir.getStepX(), dir.getStepZ());
|
||||
dir = BlocksHelper.HORIZONTAL[(i + 1) & 3];
|
||||
OFFSETS[i + 12] = new Point(OFFSETS[inner].x + dir.getOffsetX(), OFFSETS[inner].y + dir.getOffsetZ());
|
||||
OFFSETS[i + 12] = new Point(OFFSETS[inner].x + dir.getStepX(), OFFSETS[inner].y + dir.getStepZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.network.protocol.PacketUtils;
|
||||
import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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;
|
||||
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
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 {
|
||||
@Mixin(ClientPacketListener.class)
|
||||
public class ClientPlayNetworkHandlerMixin
|
||||
{
|
||||
@Shadow
|
||||
private Minecraft client;
|
||||
|
||||
|
@ -24,12 +24,12 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
private ClientLevel world;
|
||||
|
||||
@Inject(method = "onSignEditorOpen", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void be_openSignEditor(SignEditorOpenS2CPacket packet, CallbackInfo info) {
|
||||
NetworkThreadUtils.forceMainThread(packet, ClientPlayNetworkHandler.class.cast(this), client);
|
||||
public void be_openSignEditor(ClientboundOpenSignEditorPacket packet, CallbackInfo info) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, ClientPacketListener.class.cast(this), client);
|
||||
BlockEntity blockEntity = world.getBlockEntity(packet.getPos());
|
||||
if (blockEntity instanceof ESignBlockEntity) {
|
||||
ESignBlockEntity sign = (ESignBlockEntity) blockEntity;
|
||||
client.openScreen(new BlockSignEditScreen(sign));
|
||||
client.setScreen(new BlockSignEditScreen(sign));
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import net.minecraft.client.ClientRecipeBook;
|
||||
import net.minecraft.client.RecipeBookCategories;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.client.recipebook.ClientRecipeBook;
|
||||
import net.minecraft.client.recipebook.RecipeBookGroup;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import ru.betterend.interfaces.BetterEndRecipe;
|
||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||
|
||||
@Mixin(ClientRecipeBook.class)
|
||||
public abstract class ClientRecipeBookMixin {
|
||||
@Inject(method = "getGroupForRecipe", at = @At("HEAD"), cancellable = true)
|
||||
private static void be_getGroupForRecipe(Recipe<?> recipe, CallbackInfoReturnable<RecipeBookGroup> cinfo) {
|
||||
private static void be_getGroupForRecipe(Recipe<?> recipe, CallbackInfoReturnable<RecipeBookCategories> cinfo) {
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
cinfo.setReturnValue(RecipeBookGroup.BLAST_FURNACE_MISC);
|
||||
cinfo.setReturnValue(RecipeBookCategories.BLAST_FURNACE_MISC);
|
||||
} else if (recipe instanceof BetterEndRecipe) {
|
||||
cinfo.setReturnValue(RecipeBookGroup.UNKNOWN);
|
||||
cinfo.setReturnValue(RecipeBookCategories.UNKNOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,9 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.minecraft.client.renderer.block.model.BlockModelDefinition;
|
||||
|
||||
import net.minecraft.client.render.model.json.ModelVariantMap;
|
||||
|
||||
@Mixin(ModelVariantMap.DeserializationContext.class)
|
||||
@Mixin(BlockModelDefinition.Context.class)
|
||||
public interface ContextGsonAccessor {
|
||||
@Accessor
|
||||
public Gson getGson();
|
||||
|
|
|
@ -1,27 +1,25 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EnchantmentTableBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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.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)
|
||||
@Mixin(EnchantmentTableBlock.class)
|
||||
public abstract class EnchantingTableBlockMixin extends Block {
|
||||
public EnchantingTableBlockMixin(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Inject(method = "animateTick", at = @At(value = "TAIL"))
|
||||
@Inject(method = "randomDisplayTick", 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) {
|
||||
|
@ -31,13 +29,11 @@ public abstract class EnchantingTableBlockMixin extends Block {
|
|||
if (random.nextInt(16) == 0) {
|
||||
for (int py = 0; py <= 1; ++py) {
|
||||
BlockPos blockPos = pos.offset(px, py, pz);
|
||||
if (world.getBlockState(blockPos).isIn(EndTags.BOOKSHELVES)) {
|
||||
if (!world.isAir(pos.offset(px / 2, 0, pz / 2))) {
|
||||
if (world.getBlockState(blockPos).is(EndTags.BOOKSHELVES)) {
|
||||
if (!world.isEmptyBlock(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,18 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.RunArgs;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
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.gui.Gui;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.WinScreen;
|
||||
import net.minecraft.client.main.GameConfig;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.sound.MusicSound;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.Musics;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.interfaces.IColorProvider;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
@ -27,18 +26,18 @@ import ru.betterend.util.MHelper;
|
|||
@Mixin(Minecraft.class)
|
||||
public class MinecraftClientMixin {
|
||||
@Shadow
|
||||
public ClientPlayerEntity player;
|
||||
|
||||
public LocalPlayer player;
|
||||
|
||||
@Shadow
|
||||
public Screen currentScreen;
|
||||
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
public InGameHud inGameHud;
|
||||
|
||||
public Gui inGameHud;
|
||||
|
||||
@Shadow
|
||||
public ClientLevel world;
|
||||
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private BlockColors blockColors;
|
||||
|
@ -46,28 +45,27 @@ public class MinecraftClientMixin {
|
|||
@Shadow
|
||||
@Final
|
||||
private ItemColors itemColors;
|
||||
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void be_onInit(RunArgs args, CallbackInfo info) {
|
||||
private void be_onInit(GameConfig args, CallbackInfo info) {
|
||||
Registry.BLOCK.forEach(block -> {
|
||||
if (block instanceof IColorProvider) {
|
||||
IColorProvider provider = (IColorProvider) block;
|
||||
blockColors.registerColorProvider(provider.getBlockProvider(), block);
|
||||
blockColors.register(provider.getProvider(), 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.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);
|
||||
private void be_getEndMusic(CallbackInfoReturnable<Music> info) {
|
||||
if (!(this.currentScreen instanceof WinScreen) && this.player != null) {
|
||||
if (this.player.level.dimension() == Level.END) {
|
||||
if (this.inGameHud.getBossOverlay().shouldPlayMusic() && MHelper.lengthSqr(this.player.getX(), this.player.getZ()) < 250000) {
|
||||
info.setReturnValue(Musics.END_BOSS);
|
||||
}
|
||||
else {
|
||||
Music sound = (Music) this.world.getBiomeManager().getNoiseBiomeAtPosition(this.player.blockPosition()).getBackgroundMusic().orElse(Musics.END);
|
||||
info.setReturnValue(sound);
|
||||
}
|
||||
info.cancel();
|
||||
|
|
|
@ -4,7 +4,14 @@ import java.io.InputStreamReader;
|
|||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
@ -12,40 +19,31 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
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.world.level.block.Block;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.render.model.json.JsonUnbakedModel;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
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;
|
||||
|
||||
@Mixin(ModelLoader.class)
|
||||
@Mixin(ModelBakery.class)
|
||||
public class ModelLoaderMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
|
||||
@Inject(method = "loadModelFromJson", at = @At("HEAD"), cancellable = true)
|
||||
private void be_loadModelPattern(ResourceLocation id, CallbackInfoReturnable<JsonUnbakedModel> info) {
|
||||
private void be_loadModelPattern(ResourceLocation id, CallbackInfoReturnable<BlockModel> info) {
|
||||
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
|
||||
ResourceLocation modelId = new ResourceLocation(id.getNamespace(), "models/" + id.getPath() + ".json");
|
||||
JsonUnbakedModel model;
|
||||
BlockModel model;
|
||||
try (Resource resource = this.resourceManager.getResource(modelId)) {
|
||||
Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8);
|
||||
model = JsonUnbakedModel.deserialize(reader);
|
||||
model.id = id.toString();
|
||||
model = BlockModel.fromStream(reader);
|
||||
model.name = id.toString();
|
||||
info.setReturnValue(model);
|
||||
} catch (Exception ex) {
|
||||
String data[] = id.getPath().split("/");
|
||||
if (data.length > 1) {
|
||||
ResourceLocation itemId = new ResourceLocation(id.getNamespace(), data[1]);
|
||||
Optional<Block> block = Registry.BLOCK.getOrEmpty(itemId);
|
||||
Optional<Block> block = Registry.BLOCK.getOptional(itemId);
|
||||
if (block.isPresent()) {
|
||||
if (block.get() instanceof Patterned) {
|
||||
Patterned patterned = (Patterned) block.get();
|
||||
|
@ -53,7 +51,7 @@ public class ModelLoaderMixin {
|
|||
info.setReturnValue(model);
|
||||
}
|
||||
} else {
|
||||
Optional<Item> item = Registry.ITEM.getOrEmpty(itemId);
|
||||
Optional<Item> item = Registry.ITEM.getOptional(itemId);
|
||||
if (item.isPresent() && item.get() instanceof Patterned) {
|
||||
Patterned patterned = (Patterned) item.get();
|
||||
model = this.be_getModel(data, id, patterned);
|
||||
|
@ -64,8 +62,8 @@ public class ModelLoaderMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JsonUnbakedModel be_getModel(String data[], ResourceLocation id, Patterned patterned) {
|
||||
|
||||
private BlockModel be_getModel(String data[], ResourceLocation id, Patterned patterned) {
|
||||
String pattern;
|
||||
if (id.getPath().contains("item")) {
|
||||
pattern = patterned.getModelPattern(id.getPath());
|
||||
|
@ -76,17 +74,15 @@ public class ModelLoaderMixin {
|
|||
pattern = patterned.getModelPattern(data[1]);
|
||||
}
|
||||
}
|
||||
JsonUnbakedModel model = JsonUnbakedModel.deserialize(pattern);
|
||||
model.id = id.toString();
|
||||
|
||||
BlockModel model = BlockModel.fromString(pattern);
|
||||
model.name = id.toString();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
@ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE"))
|
||||
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_")) {
|
||||
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;
|
||||
|
|
|
@ -2,30 +2,27 @@ package ru.betterend.mixin.client;
|
|||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModelDefinition;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
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)
|
||||
@Mixin(BlockModelDefinition.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().defaultBlockState().getBlock();
|
||||
private static void be_deserializeBlockState(BlockModelDefinition.Context context, Reader reader, CallbackInfoReturnable<BlockModelDefinition> info) {
|
||||
Block block = context.getDefinition().any().getBlock();
|
||||
if (block instanceof BlockPatterned) {
|
||||
String pattern = ((BlockPatterned) block).getStatesPattern(reader);
|
||||
Gson gson = ContextGsonAccessor.class.cast(context).getGson();
|
||||
ModelVariantMap map = JsonHelper.deserialize(gson, new StringReader(pattern), ModelVariantMap.class);
|
||||
BlockModelDefinition map = GsonHelper.fromJson(gson, new StringReader(pattern), BlockModelDefinition.class);
|
||||
info.setReturnValue(map);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,47 +1,45 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.MusicManager;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.client.ClientOptions;
|
||||
|
||||
@Mixin(MusicTracker.class)
|
||||
@Mixin(MusicManager.class)
|
||||
public class MusicTrackerMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private Minecraft 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()) {
|
||||
MusicSound musicSound = client.getMusicType();
|
||||
Music musicSound = client.getSituationalMusic();
|
||||
if (be_checkNullSound(musicSound) && volume > 0 && be_isInEnd() && be_shouldChangeSound(musicSound)) {
|
||||
if (volume > 0) {
|
||||
if (srcVolume < 0) {
|
||||
|
@ -50,7 +48,7 @@ public class MusicTrackerMixin {
|
|||
if (current instanceof AbstractSoundInstance) {
|
||||
((AbstractSoundInstanceAccessor) current).setVolume(volume);
|
||||
}
|
||||
client.getSoundManager().updateSoundVolume(current.getCategory(), current.getVolume() * volume);
|
||||
client.getSoundManager().updateSourceVolume(current.getSource(), current.getVolume() * volume);
|
||||
long t = System.currentTimeMillis();
|
||||
if (volume == 1 && time == 0) {
|
||||
time = t;
|
||||
|
@ -74,26 +72,25 @@ public class MusicTrackerMixin {
|
|||
this.play(musicSound);
|
||||
}
|
||||
info.cancel();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
volume = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean be_isInEnd() {
|
||||
return client.world != null && client.world.dimension().equals(Level.END);
|
||||
return client.level != null && client.level.dimension().equals(Level.END);
|
||||
}
|
||||
|
||||
private boolean be_shouldChangeSound(MusicSound musicSound) {
|
||||
return current != null && !musicSound.getSound().getId().equals(this.current.getId())
|
||||
&& musicSound.shouldReplaceCurrentMusic();
|
||||
|
||||
private boolean be_shouldChangeSound(Music musicSound) {
|
||||
return current != null && !musicSound.getEvent().getLocation().equals(this.current.getLocation()) && musicSound.replaceCurrentMusic();
|
||||
}
|
||||
|
||||
private boolean be_checkNullSound(MusicSound musicSound) {
|
||||
return musicSound != null && musicSound.getSound() != null;
|
||||
|
||||
private boolean be_checkNullSound(Music musicSound) {
|
||||
return musicSound != null && musicSound.getEvent() != null;
|
||||
}
|
||||
|
||||
|
||||
@Shadow
|
||||
public void play(MusicSound type) {
|
||||
}
|
||||
public void play(Music type) {}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.FallbackResourceManager;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
@ -10,22 +14,19 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.resource.NamespaceResourceManager;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.Registry;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.patterns.BlockPatterned;
|
||||
|
||||
@Mixin(NamespaceResourceManager.class)
|
||||
@Mixin(FallbackResourceManager.class)
|
||||
public abstract class NamespaceResourceManagerMixin {
|
||||
|
||||
|
||||
@Shadow
|
||||
public abstract Resource getResource(ResourceLocation id);
|
||||
|
||||
@Inject(method = "getAllResources", cancellable = true, at = @At(value = "NEW", target = "java/io/FileNotFoundException", shift = Shift.BEFORE))
|
||||
|
||||
@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("/");
|
||||
|
|
|
@ -11,37 +11,36 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexBuffer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gl.VertexBuffer;
|
||||
import net.minecraft.client.render.BackgroundRenderer;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.BufferBuilderStorage;
|
||||
import net.minecraft.client.render.SkyProperties;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.DimensionSpecialEffects;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.RenderBuffers;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.client.ClientOptions;
|
||||
import ru.betterend.util.BackgroundInfo;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
@Mixin(WorldRenderer.class)
|
||||
@Mixin(LevelRenderer.class)
|
||||
public class WorldRendererMixin {
|
||||
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,23 +59,23 @@ public class WorldRendererMixin {
|
|||
private static float blind02;
|
||||
private static float blind06;
|
||||
private static boolean directOpenGL = false;
|
||||
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Minecraft client;
|
||||
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private TextureManager textureManager;
|
||||
|
||||
|
||||
@Shadow
|
||||
private ClientLevel world;
|
||||
|
||||
|
||||
@Shadow
|
||||
private int ticks;
|
||||
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void be_onInit(Minecraft client, BufferBuilderStorage bufferBuilders, CallbackInfo info) {
|
||||
private void be_onInit(Minecraft client, RenderBuffers bufferBuilders, CallbackInfo info) {
|
||||
be_initStars();
|
||||
Random random = new Random(131);
|
||||
axis1 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
|
@ -87,110 +86,107 @@ 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) {
|
||||
private void be_renderBetterEndSky(PoseStack matrices, float tickDelta, CallbackInfo info) {
|
||||
if (ClientOptions.isCustomSky() && client.level.effects().skyType() == DimensionSpecialEffects.SkyType.END) {
|
||||
time = (ticks % 360000) * 0.000017453292F;
|
||||
time2 = time * 2;
|
||||
time3 = time * 3;
|
||||
|
||||
BackgroundRenderer.setFogBlack();
|
||||
|
||||
FogRenderer.levelFogColor();
|
||||
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();
|
||||
matrices.pushPose();
|
||||
matrices.mulPose(new Quaternion(0, time, 0, false));
|
||||
textureManager.bind(HORIZON);
|
||||
be_renderBuffer(matrices, horizon, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, 0.7F * blindA);
|
||||
matrices.popPose();
|
||||
|
||||
matrices.pushPose();
|
||||
matrices.mulPose(new Quaternion(0, -time, 0, false));
|
||||
textureManager.bind(NEBULA_1);
|
||||
be_renderBuffer(matrices, nebulas1, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02);
|
||||
matrices.popPose();
|
||||
|
||||
matrices.pushPose();
|
||||
matrices.mulPose(new Quaternion(0, time2, 0, false));
|
||||
textureManager.bind(NEBULA_2);
|
||||
be_renderBuffer(matrices, nebulas2, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02);
|
||||
matrices.popPose();
|
||||
|
||||
textureManager.bind(STARS);
|
||||
|
||||
matrices.pushPose();
|
||||
matrices.mulPose(axis3.rotation(time));
|
||||
be_renderBuffer(matrices, stars3, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind06);
|
||||
matrices.popPose();
|
||||
|
||||
matrices.pushPose();
|
||||
matrices.mulPose(axis4.rotation(time2));
|
||||
be_renderBuffer(matrices, stars4, DefaultVertexFormat.POSITION_TEX, 1F, 1F, 1F, blind06);
|
||||
matrices.popPose();
|
||||
}
|
||||
|
||||
|
||||
float a = (BackgroundInfo.fog - 1F);
|
||||
if (a > 0) {
|
||||
if (a > 1)
|
||||
a = 1;
|
||||
textureManager.bindTexture(FOG);
|
||||
be_renderBuffer(matrices, fog, VertexFormats.POSITION_TEXTURE, BackgroundInfo.red, BackgroundInfo.green,
|
||||
BackgroundInfo.blue, a);
|
||||
if (a > 1) a = 1;
|
||||
textureManager.bind(FOG);
|
||||
be_renderBuffer(matrices, fog, DefaultVertexFormat.POSITION_TEX, 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();
|
||||
matrices.pushPose();
|
||||
matrices.mulPose(axis1.rotation(time3));
|
||||
be_renderBuffer(matrices, stars1, DefaultVertexFormat.POSITION, 1, 1, 1, blind06);
|
||||
matrices.popPose();
|
||||
|
||||
matrices.pushPose();
|
||||
matrices.mulPose(axis2.rotation(time2));
|
||||
be_renderBuffer(matrices, stars2, DefaultVertexFormat.POSITION, 0.95F, 0.64F, 0.93F, blind06);
|
||||
matrices.popPose();
|
||||
}
|
||||
|
||||
|
||||
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(PoseStack 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();
|
||||
format.setupBufferState(0L);
|
||||
buffer.draw(matrices.last().pose(), 7);
|
||||
VertexBuffer.unbind();
|
||||
format.clearBufferState();
|
||||
}
|
||||
|
||||
private void be_initStars() {
|
||||
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
|
||||
BufferBuilder buffer = Tesselator.getInstance().getBuilder();
|
||||
stars1 = be_buildBufferStars(buffer, stars1, 0.1, 0.30, 3500, 41315);
|
||||
stars2 = be_buildBufferStars(buffer, stars2, 0.1, 0.35, 2000, 35151);
|
||||
stars3 = be_buildBufferUVStars(buffer, stars3, 0.4, 1.2, 1000, 61354);
|
||||
|
@ -200,78 +196,75 @@ 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();
|
||||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION);
|
||||
buffer = new VertexBuffer(DefaultVertexFormat.POSITION);
|
||||
be_makeStars(bufferBuilder, minSize, maxSize, count, seed);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE);
|
||||
buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
|
||||
be_makeUVStars(bufferBuilder, minSize, maxSize, count, seed);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE);
|
||||
buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
|
||||
be_makeFarFog(bufferBuilder, minSize, maxSize, count, seed);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
private VertexBuffer be_buildBufferHorizon(BufferBuilder bufferBuilder, VertexBuffer buffer) {
|
||||
if (buffer != null) {
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE);
|
||||
buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
|
||||
be_makeCylinder(bufferBuilder, 16, 50, 100);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
private VertexBuffer be_buildBufferFog(BufferBuilder bufferBuilder, VertexBuffer buffer) {
|
||||
if (buffer != null) {
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE);
|
||||
buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
|
||||
be_makeCylinder(bufferBuilder, 16, 50, 70);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
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);
|
||||
buffer.begin(7, DefaultVertexFormat.POSITION);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
double posX = random.nextDouble() * 2.0 - 1.0;
|
||||
|
@ -306,15 +299,15 @@ public class WorldRendererMixin {
|
|||
double ae = 0.0 * q - aa * r;
|
||||
double af = ae * n - ab * o;
|
||||
double ah = ab * n + ae * o;
|
||||
buffer.vertex(j + af, k + ad, l + ah).next();
|
||||
buffer.vertex(j + af, k + ad, l + ah).endVertex();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
buffer.begin(7, DefaultVertexFormat.POSITION_TEX);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
double posX = random.nextDouble() * 2.0 - 1.0;
|
||||
|
@ -353,16 +346,16 @@ public class WorldRendererMixin {
|
|||
double ah = ab * n + ae * o;
|
||||
float texU = (pos >> 1) & 1;
|
||||
float texV = (((pos + 1) >> 1) & 1) / 4F + minV;
|
||||
pos++;
|
||||
buffer.vertex(j + af, k + ad, l + ah).texture(texU, texV).next();
|
||||
pos ++;
|
||||
buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
buffer.begin(7, DefaultVertexFormat.POSITION_TEX);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
double posX = random.nextDouble() * 2.0 - 1.0;
|
||||
|
@ -404,30 +397,30 @@ public class WorldRendererMixin {
|
|||
double ah = ab * n + ae * o;
|
||||
float texU = (pos >> 1) & 1;
|
||||
float texV = ((pos + 1) >> 1) & 1;
|
||||
pos++;
|
||||
buffer.vertex(j + af, k + ad, l + ah).texture(texU, texV).next();
|
||||
pos ++;
|
||||
buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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++) {
|
||||
buffer.begin(7, DefaultVertexFormat.POSITION_TEX);
|
||||
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();
|
||||
buffer.vertex(px2, -height, pz2).texture(u1, 0).next();
|
||||
|
||||
buffer.vertex(px1, -height, pz1).uv(u0, 0).endVertex();
|
||||
buffer.vertex(px1, height, pz1).uv(u0, 1).endVertex();
|
||||
buffer.vertex(px2, height, pz2).uv(u1, 1).endVertex();
|
||||
buffer.vertex(px2, -height, pz2).uv(u1, 0).endVertex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue