Reorganized Imports/Packages
This commit is contained in:
parent
cb9459f176
commit
3ee10482ab
721 changed files with 34873 additions and 33558 deletions
|
@ -0,0 +1,93 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
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.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 com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import org.betterx.bclib.interfaces.AnvilScreenHandlerExtended;
|
||||
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 java.util.List;
|
||||
|
||||
@Mixin(AnvilScreen.class)
|
||||
public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
|
||||
|
||||
@Shadow
|
||||
private EditBox name;
|
||||
|
||||
private final List<AbstractWidget> be_buttons = Lists.newArrayList();
|
||||
|
||||
public AnvilScreenMixin(AnvilMenu handler, Inventory playerInventory, Component title, ResourceLocation texture) {
|
||||
super(handler, playerInventory, title, texture);
|
||||
}
|
||||
|
||||
@Inject(method = "subInit", at = @At("TAIL"))
|
||||
protected void be_subInit(CallbackInfo info) {
|
||||
int x = (width - imageWidth) / 2;
|
||||
int y = (height - imageHeight) / 2;
|
||||
be_buttons.clear();
|
||||
be_buttons.add(new Button(x + 8, y + 45, 15, 20, Component.literal("<"), b -> be_previousRecipe()));
|
||||
be_buttons.add(new Button(x + 154, y + 45, 15, 20, Component.literal(">"), b -> be_nextRecipe()));
|
||||
}
|
||||
|
||||
@Inject(method = "renderFg", at = @At("TAIL"))
|
||||
protected void be_renderForeground(PoseStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
|
||||
be_buttons.forEach(button -> {
|
||||
button.render(matrices, mouseX, mouseY, delta);
|
||||
});
|
||||
}
|
||||
|
||||
@Inject(method = "slotChanged", at = @At("HEAD"), cancellable = true)
|
||||
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) {
|
||||
be_buttons.forEach(button -> button.visible = true);
|
||||
} else {
|
||||
be_buttons.forEach(button -> button.visible = false);
|
||||
}
|
||||
name.setValue("");
|
||||
info.cancel();
|
||||
} else {
|
||||
be_buttons.forEach(button -> button.visible = false);
|
||||
}
|
||||
}
|
||||
|
||||
private void be_nextRecipe() {
|
||||
((AnvilScreenHandlerExtended) menu).be_nextRecipe();
|
||||
}
|
||||
|
||||
private void be_previousRecipe() {
|
||||
((AnvilScreenHandlerExtended) menu).be_previousRecipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (minecraft != null) {
|
||||
for (AbstractWidget elem : be_buttons) {
|
||||
if (elem.visible && elem.mouseClicked(mouseX, mouseY, button)) {
|
||||
if (minecraft.gameMode != null) {
|
||||
int i = be_buttons.indexOf(elem);
|
||||
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
}
|
30
src/main/java/org/betterx/bclib/mixin/client/BlockMixin.java
Normal file
30
src/main/java/org/betterx/bclib/mixin/client/BlockMixin.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import org.betterx.bclib.interfaces.SurvivesOnSpecialGround;
|
||||
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 java.util.List;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Mixin(Block.class)
|
||||
public class BlockMixin {
|
||||
@Inject(method = "appendHoverText", at = @At("HEAD"))
|
||||
void bclib_appendSurvivalBlock(ItemStack itemStack,
|
||||
@Nullable BlockGetter blockGetter,
|
||||
List<Component> list,
|
||||
TooltipFlag tooltipFlag,
|
||||
CallbackInfo ci) {
|
||||
if (this instanceof SurvivesOnSpecialGround surv) {
|
||||
SurvivesOnSpecialGround.appendHoverText(list, surv.getSurvivableBlocksString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.ClientRecipeBook;
|
||||
import net.minecraft.client.RecipeBookCategories;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
|
||||
import org.betterx.bclib.interfaces.UnknownReceipBookCategory;
|
||||
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;
|
||||
|
||||
@Mixin(ClientRecipeBook.class)
|
||||
public abstract class ClientRecipeBookMixin {
|
||||
@Inject(method = "getCategory", at = @At("HEAD"), cancellable = true)
|
||||
private static void be_getGroupForRecipe(Recipe<?> recipe, CallbackInfoReturnable<RecipeBookCategories> info) {
|
||||
if (recipe instanceof UnknownReceipBookCategory) {
|
||||
info.setReturnValue(RecipeBookCategories.UNKNOWN);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
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;
|
||||
|
||||
@Mixin(CreateWorldScreen.class)
|
||||
public class CreateWorldScreenMixin {
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void bcl_init(Screen screen,
|
||||
DataPackConfig dataPackConfig,
|
||||
WorldGenSettingsComponent worldGenSettingsComponent,
|
||||
CallbackInfo ci) {
|
||||
BiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder().registryOrThrow(Registry.BIOME_REGISTRY));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
|
||||
import org.betterx.bclib.client.render.CustomFogRenderer;
|
||||
import org.betterx.bclib.util.BackgroundInfo;
|
||||
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;
|
||||
|
||||
@Mixin(FogRenderer.class)
|
||||
public class FogRendererMixin {
|
||||
@Shadow
|
||||
private static float fogRed;
|
||||
@Shadow
|
||||
private static float fogGreen;
|
||||
@Shadow
|
||||
private static float fogBlue;
|
||||
|
||||
@Inject(method = "setupColor", at = @At("RETURN"))
|
||||
private static void bclib_onRender(Camera camera,
|
||||
float tickDelta,
|
||||
ClientLevel world,
|
||||
int i,
|
||||
float f,
|
||||
CallbackInfo info) {
|
||||
FogType fogType = camera.getFluidInCamera();
|
||||
if (fogType != FogType.WATER && world.dimension().equals(Level.END)) {
|
||||
Entity entity = camera.getEntity();
|
||||
boolean skip = false;
|
||||
if (entity instanceof LivingEntity) {
|
||||
MobEffectInstance effect = ((LivingEntity) entity).getEffect(MobEffects.NIGHT_VISION);
|
||||
skip = effect != null && effect.getDuration() > 0;
|
||||
}
|
||||
if (!skip) {
|
||||
fogRed *= 4;
|
||||
fogGreen *= 4;
|
||||
fogBlue *= 4;
|
||||
}
|
||||
}
|
||||
|
||||
BackgroundInfo.fogColorRed = fogRed;
|
||||
BackgroundInfo.fogColorGreen = fogGreen;
|
||||
BackgroundInfo.fogColorBlue = fogBlue;
|
||||
}
|
||||
|
||||
@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true)
|
||||
private static void bclib_fogDensity(Camera camera,
|
||||
FogRenderer.FogMode fogMode,
|
||||
float viewDistance,
|
||||
boolean thickFog,
|
||||
float g,
|
||||
CallbackInfo ci) {
|
||||
if (CustomFogRenderer.applyFogDensity(camera, viewDistance, thickFog)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
18
src/main/java/org/betterx/bclib/mixin/client/GameMixin.java
Normal file
18
src/main/java/org/betterx/bclib/mixin/client/GameMixin.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.Game;
|
||||
|
||||
import org.betterx.bclib.api.dataexchange.DataExchangeAPI;
|
||||
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;
|
||||
|
||||
@Mixin(Game.class)
|
||||
public class GameMixin {
|
||||
|
||||
@Inject(method = "onStartGameSession", at = @At("TAIL"))
|
||||
public void bclib_onStart(CallbackInfo ci) {
|
||||
DataExchangeAPI.sendOnEnter();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.client.main.GameConfig;
|
||||
import net.minecraft.core.Registry;
|
||||
|
||||
import org.betterx.bclib.interfaces.CustomColorProvider;
|
||||
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;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MinecraftMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private BlockColors blockColors;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
private ItemColors itemColors;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void bclib_onMCInit(GameConfig args, CallbackInfo info) {
|
||||
Registry.BLOCK.forEach(block -> {
|
||||
if (block instanceof CustomColorProvider provider) {
|
||||
blockColors.register(provider.getProvider(), block);
|
||||
itemColors.register(provider.getItemProvider(), block.asItem());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
|
||||
import org.betterx.bclib.api.ModIntegrationAPI;
|
||||
import org.betterx.bclib.client.models.CustomModelBakery;
|
||||
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 java.util.Map;
|
||||
|
||||
@Mixin(ModelBakery.class)
|
||||
public abstract class ModelBakeryMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private Map<ResourceLocation, UnbakedModel> unbakedCache;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void bclib_findEmissiveModels(ResourceManager resourceManager,
|
||||
BlockColors blockColors,
|
||||
ProfilerFiller profiler,
|
||||
int mipmap,
|
||||
CallbackInfo info) {
|
||||
//CustomModelBakery.setModelsLoaded(false);
|
||||
if (ModIntegrationAPI.hasCanvas()) {
|
||||
CustomModelBakery.loadEmissiveModels(unbakedCache);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
|
||||
import org.betterx.bclib.client.BCLibClient;
|
||||
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;
|
||||
|
||||
@Mixin(ModelManager.class)
|
||||
public class ModelManagerMixin {
|
||||
@Inject(method = "prepare", at = @At("HEAD"))
|
||||
private void bclib_loadCustomModels(ResourceManager resourceManager,
|
||||
ProfilerFiller profilerFiller,
|
||||
CallbackInfoReturnable<ModelBakery> info) {
|
||||
BCLibClient.modelBakery.loadCustomModels(resourceManager);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.FallbackResourceManager;
|
||||
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.ModIntegrationAPI;
|
||||
import org.betterx.bclib.client.render.EmissiveTextureInfo;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(MultiPackResourceManager.class)
|
||||
public class MultiPackResourceManagerMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private Map<String, FallbackResourceManager> namespacedManagers;
|
||||
|
||||
private final ResourceLocation bclib_alphaEmissionMaterial = BCLib.makeID("materialmaps/block/alpha_emission.json");
|
||||
|
||||
@Inject(method = "getResource", at = @At("HEAD"), cancellable = true)
|
||||
private void bclib_getResource(ResourceLocation resourceLocation,
|
||||
CallbackInfoReturnable<Resource> info) throws IOException {
|
||||
if (!ModIntegrationAPI.hasCanvas()) {
|
||||
return;
|
||||
}
|
||||
if (!resourceLocation.getPath().startsWith("materialmaps")) {
|
||||
return;
|
||||
}
|
||||
if (!resourceLocation.getPath().contains("/block/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = resourceLocation.getPath().replace("materialmaps/block/", "").replace(".json", "");
|
||||
ResourceLocation blockID = new ResourceLocation(resourceLocation.getNamespace(), name);
|
||||
|
||||
if (!EmissiveTextureInfo.isEmissiveBlock(blockID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceManager resourceManager = this.namespacedManagers.get(resourceLocation.getNamespace());
|
||||
if (resourceManager != null && resourceManager.getResource(resourceLocation).isEmpty()) {
|
||||
info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial).get());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.SignEditScreen;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import org.betterx.bclib.blocks.BaseSignBlock;
|
||||
import org.betterx.bclib.client.render.BaseSignBlockEntityRenderer;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.At.Shift;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(SignEditScreen.class)
|
||||
public abstract class SignEditScreenMixin extends Screen {
|
||||
@Shadow
|
||||
@Final
|
||||
private SignBlockEntity sign;
|
||||
@Shadow
|
||||
private SignRenderer.SignModel signModel;
|
||||
@Unique
|
||||
private boolean bclib_renderStick;
|
||||
@Unique
|
||||
private boolean bclib_isSign;
|
||||
|
||||
protected SignEditScreenMixin(Component component) {
|
||||
super(component);
|
||||
}
|
||||
|
||||
@Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V",
|
||||
shift = Shift.BEFORE
|
||||
), locals = LocalCapture.CAPTURE_FAILSOFT)
|
||||
private void bclib_checkOffset(PoseStack poseStack,
|
||||
int i,
|
||||
int j,
|
||||
float f,
|
||||
CallbackInfo info,
|
||||
float g,
|
||||
BlockState blockState,
|
||||
boolean bl,
|
||||
boolean bl2,
|
||||
float h) {
|
||||
bclib_isSign = blockState.getBlock() instanceof BaseSignBlock;
|
||||
if (bclib_isSign) {
|
||||
bclib_renderStick = blockState.getValue(BaseSignBlock.FLOOR);
|
||||
if (bclib_renderStick) {
|
||||
poseStack.translate(0.0, 0.3125, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyArg(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/geom/ModelPart;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;II)V"), index = 1)
|
||||
private VertexConsumer bclib_signRender(VertexConsumer consumer) {
|
||||
if (bclib_isSign) {
|
||||
signModel.stick.visible = bclib_renderStick;
|
||||
Block block = sign.getBlockState().getBlock();
|
||||
MultiBufferSource.BufferSource bufferSource = this.minecraft.renderBuffers().bufferSource();
|
||||
return BaseSignBlockEntityRenderer.getConsumer(bufferSource, block);
|
||||
}
|
||||
return consumer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
||||
import net.fabricmc.fabric.impl.client.texture.FabricSprite;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.client.render.EmissiveTextureInfo;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(TextureAtlas.class)
|
||||
public class TextureAtlasMixin {
|
||||
private static final int EMISSIVE_ALPHA = 254 << 24;
|
||||
private boolean bclib_modifyAtlas;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void bclib_onAtlasInit(ResourceLocation resourceLocation, CallbackInfo info) {
|
||||
boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");
|
||||
bclib_modifyAtlas = !hasOptifine && resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
|
||||
if (bclib_modifyAtlas) {
|
||||
EmissiveTextureInfo.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", at = @At("HEAD"), cancellable = true)
|
||||
private void bclib_loadSprite(ResourceManager resourceManager,
|
||||
TextureAtlasSprite.Info spriteInfo,
|
||||
int atlasWidth,
|
||||
int atlasHeight,
|
||||
int maxLevel,
|
||||
int posX,
|
||||
int posY,
|
||||
CallbackInfoReturnable<TextureAtlasSprite> info) {
|
||||
if (!bclib_modifyAtlas) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation location = spriteInfo.name();
|
||||
if (!location.getPath().startsWith("block")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation emissiveLocation = new ResourceLocation(
|
||||
location.getNamespace(),
|
||||
"textures/" + location.getPath() + "_e.png"
|
||||
);
|
||||
Optional<Resource> emissiveRes = resourceManager.getResource(emissiveLocation);
|
||||
if (emissiveRes.isPresent()) {
|
||||
NativeImage sprite = null;
|
||||
NativeImage emission = null;
|
||||
try {
|
||||
ResourceLocation spriteLocation = new ResourceLocation(
|
||||
location.getNamespace(),
|
||||
"textures/" + location.getPath() + ".png"
|
||||
);
|
||||
Resource resource = resourceManager.getResource(spriteLocation).orElse(null);
|
||||
sprite = NativeImage.read(resource.open());
|
||||
|
||||
resource = emissiveRes.get();
|
||||
emission = NativeImage.read(resource.open());
|
||||
} catch (IOException e) {
|
||||
BCLib.LOGGER.warning(e.getMessage());
|
||||
}
|
||||
if (sprite != null && emission != null) {
|
||||
int width = Math.min(sprite.getWidth(), emission.getWidth());
|
||||
int height = Math.min(sprite.getHeight(), emission.getHeight());
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int argb = emission.getPixelRGBA(x, y);
|
||||
int alpha = (argb >> 24) & 255;
|
||||
if (alpha > 127) {
|
||||
int r = (argb >> 16) & 255;
|
||||
int g = (argb >> 8) & 255;
|
||||
int b = argb & 255;
|
||||
if (r > 0 || g > 0 || b > 0) {
|
||||
argb = (argb & 0x00FFFFFF) | EMISSIVE_ALPHA;
|
||||
sprite.setPixelRGBA(x, y, argb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TextureAtlas self = (TextureAtlas) (Object) this;
|
||||
FabricSprite result = new FabricSprite(
|
||||
self,
|
||||
spriteInfo,
|
||||
maxLevel,
|
||||
atlasWidth,
|
||||
atlasHeight,
|
||||
posX,
|
||||
posY,
|
||||
sprite
|
||||
);
|
||||
EmissiveTextureInfo.addTexture(location);
|
||||
info.setReturnValue(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue