mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-18 14:35:09 +01:00
Port to 1.21
- Rewrite packet system to use vanilla payloads - Water bottles will now appear slightly transparent - One of the hardest 1.21 ports yet
This commit is contained in:
@@ -8,7 +8,6 @@ import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.texture.*;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
@@ -33,7 +32,7 @@ public class IconicButtons {
|
||||
iconId = Identifier.tryParse("iconic:textures/gui/icons/" + buttonId.toLowerCase()+".png");
|
||||
if (buttonId.endsWith(".midnightconfig.title"))
|
||||
{
|
||||
iconId = new Identifier("modid", buttonId.replace(".midnightconfig.title", "") + "_icon");
|
||||
iconId = Identifier.of("modid", buttonId.replace(".midnightconfig.title", "") + "_icon");
|
||||
NativeImageBackedTexture icon = new ModIconUtil(buttonId.replace(".midnightconfig.title", "")).createModIcon();
|
||||
if (icon != null) {
|
||||
client.getTextureManager().registerTexture(iconId, icon);
|
||||
@@ -84,13 +83,13 @@ public class IconicButtons {
|
||||
manager.findResources("textures", path -> path.getPath().contains(".properties")).forEach((id, resource) -> {
|
||||
if (manager.getResource(id).isEmpty()) return;
|
||||
try (InputStream stream = manager.getResource(id).get().getInputStream()) {
|
||||
Identifier iconId = new Identifier(id.getNamespace(), id.getPath().replace(".properties", ".png"));
|
||||
Identifier iconId = Identifier.of(id.getNamespace(), id.getPath().replace(".properties", ".png"));
|
||||
if (manager.getResource(iconId).isPresent()) return;
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.load(stream);
|
||||
while (properties.get("properties") != null) {
|
||||
Identifier propertiesId = new Identifier(properties.getProperty("properties"));
|
||||
Identifier propertiesId = Identifier.of(properties.getProperty("properties"));
|
||||
String textureId = propertiesId.toString().replace(".properties", ".png");
|
||||
|
||||
properties.clear();
|
||||
@@ -103,7 +102,7 @@ public class IconicButtons {
|
||||
}
|
||||
|
||||
if (properties.get("texture") != null) {
|
||||
Identifier textureId = new Identifier(properties.getProperty("texture"));
|
||||
Identifier textureId = Identifier.of(properties.getProperty("texture"));
|
||||
TextureManager textureManager = MinecraftClient.getInstance().getTextureManager();
|
||||
AbstractTexture abstractTexture = textureManager.getOrDefault(iconId, null);
|
||||
if (abstractTexture == null) {
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package eu.midnightdust.visualoverhaul;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VisualOverhaul {
|
||||
public static final String MOD_ID = "visualoverhaul";
|
||||
public static final List<UUID> playersWithMod = Lists.newArrayList();
|
||||
public static final Map<BlockPos, ItemStack> jukeboxItems = new HashMap<>();
|
||||
|
||||
public static final Identifier HELLO_PACKET = new Identifier(MOD_ID, "hello");
|
||||
public static final Identifier UPDATE_POTION_BOTTLES = new Identifier(MOD_ID, "brewingstand");
|
||||
public static final Identifier UPDATE_RECORD = new Identifier(MOD_ID, "record");
|
||||
public static final Identifier UPDATE_FURNACE_ITEMS = new Identifier(MOD_ID, "furnace");
|
||||
}
|
||||
@@ -3,9 +3,13 @@ package eu.midnightdust.visualoverhaul;
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.MOD_ID;
|
||||
|
||||
public class VisualOverhaulClient {
|
||||
public static int waterColor = 4159204;
|
||||
public static int foliageColor = -8934609;
|
||||
public static int grassColor = -8934609;
|
||||
public static int potionColor = -13083194;
|
||||
|
||||
public static Block JukeBoxTop;
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package eu.midnightdust.visualoverhaul;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VisualOverhaulCommon {
|
||||
public static final String MOD_ID = "visualoverhaul";
|
||||
public static final List<UUID> playersWithMod = Lists.newArrayList();
|
||||
public static final Map<BlockPos, ItemStack> jukeboxItems = new HashMap<>();
|
||||
|
||||
public static final Identifier HELLO_PACKET = id("hello");
|
||||
public static final Identifier UPDATE_ITEMS_PACKET = id("update_items");
|
||||
|
||||
public static final Identifier UPDATE_TYPE_POTION_BOTTLES = id("type_brewingstand");
|
||||
public static final Identifier UPDATE_TYPE_RECORD = id("type_record");
|
||||
public static final Identifier UPDATE_TYPE_FURNACE_ITEMS = id("type_furnace");
|
||||
|
||||
public static Identifier id(String path) {
|
||||
return Identifier.of(MOD_ID, path);
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,12 @@ import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLayer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.id;
|
||||
|
||||
public class FurnaceWoodenPlanksModel extends Model {
|
||||
private static ModelPart bb_main;
|
||||
public static final EntityModelLayer WOODEN_PLANKS_MODEL_LAYER = new EntityModelLayer(new Identifier(MOD_ID, "wooden_planks"), "main");
|
||||
public static final EntityModelLayer WOODEN_PLANKS_MODEL_LAYER = new EntityModelLayer(id("wooden_planks"), "main");
|
||||
|
||||
public FurnaceWoodenPlanksModel(ModelPart root) {
|
||||
super(RenderLayer::getEntitySolid);
|
||||
@@ -35,7 +34,7 @@ public class FurnaceWoodenPlanksModel extends Model {
|
||||
return modelData;
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
|
||||
bb_main.render(matrices, vertices, light, overlay, red, green, blue, alpha);
|
||||
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
|
||||
bb_main.render(matrices, vertices, light, overlay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,6 @@ public class FurnaceBlockEntityRenderer<E extends AbstractFurnaceBlockEntity> im
|
||||
}
|
||||
public static Identifier spriteToTexture(Sprite sprite) {
|
||||
String texture = sprite.getContents().getId().getPath();
|
||||
return new Identifier(sprite.getAtlasId().getNamespace(), "textures/" + texture + ".png");
|
||||
return Identifier.of(sprite.getAtlasId().getNamespace(), "textures/" + texture + ".png");
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@ import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
|
||||
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.component.ComponentMap;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.CustomModelDataComponent;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.state.property.Properties;
|
||||
@@ -29,7 +32,7 @@ import org.joml.Quaternionf;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.jukeboxItems;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.jukeboxItems;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBlockEntity> {
|
||||
@@ -51,7 +54,7 @@ public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBl
|
||||
// Else gets the record sound played at the position of the jukebox //
|
||||
else if (SoundTest.getSound(blockEntity.getPos()) != null) {
|
||||
// Converts the Sound ID to the item ID of the appropriate disc (minecraft:music_disc.cat -> minecraft:music_disc_cat) //
|
||||
discItem = new Identifier(String.valueOf(SoundTest.getSound(blockEntity.getPos())).replace(".", "_"));
|
||||
discItem = Identifier.of(String.valueOf(SoundTest.getSound(blockEntity.getPos())).replace(".", "_"));
|
||||
|
||||
// Tries to get the disc item from the registry //
|
||||
if (Registries.ITEM.getOrEmpty(discItem).isPresent()) {
|
||||
@@ -70,7 +73,8 @@ public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBl
|
||||
}
|
||||
|
||||
if (!record.isEmpty()) {
|
||||
record.setCount(2);
|
||||
//record.setCount(2);
|
||||
record.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(710)).build());
|
||||
matrices.push();
|
||||
|
||||
matrices.translate(0.5f, 1.03f, 0.5f);
|
||||
|
||||
@@ -9,12 +9,13 @@ public class VOConfig extends MidnightConfig {
|
||||
@Client @Entry(category = blocks) public static boolean brewingstand = true;
|
||||
@Client @Entry(category = blocks) public static boolean jukebox = true;
|
||||
@Client @Entry(category = blocks) public static boolean jukebox_fake_block = true;
|
||||
@Client @Entry(category = blocks) public static boolean jukebox_clientside = true;
|
||||
@Client @Entry(category = blocks) public static boolean furnace = true;
|
||||
@Client @Entry(category = blocks) public static boolean smoker_particles = true;
|
||||
@Client @Entry(category = blocks) public static boolean blast_furnace_particles = true;
|
||||
@Client @Entry(category = colors) public static boolean coloredItems = true;
|
||||
@Client @Entry(category = colors) public static boolean coloredLilypad = true;
|
||||
@Client @Entry(category = gui) public static boolean buttonIcons = true;
|
||||
@Client @Entry(category = gui) public static boolean buttonIcons = false;
|
||||
@Client @Entry(category = gui) public static IconPosition buttonIconPosition = IconPosition.LOCATION;
|
||||
@Client @Entry(category = gui) public static boolean zoomIconOnHover = true;
|
||||
@Client @Entry(category = gui, name = "Debug") public static boolean debug = false;
|
||||
|
||||
@@ -3,12 +3,11 @@ package eu.midnightdust.visualoverhaul.mixin;
|
||||
import eu.midnightdust.visualoverhaul.util.JukeboxPacketUpdate;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(JukeboxBlockEntity.class)
|
||||
public abstract class MixinJukeboxBlockEntity extends BlockEntity {
|
||||
@@ -17,8 +16,8 @@ public abstract class MixinJukeboxBlockEntity extends BlockEntity {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack")
|
||||
public void getRecord(CallbackInfoReturnable<ItemStack> cir) {
|
||||
@Inject(at = @At("TAIL"), method = "onRecordStackChanged")
|
||||
public void getRecord(CallbackInfo ci) {
|
||||
JukeboxPacketUpdate.invUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.midnightdust.visualoverhaul.packet;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record HelloPacket(UUID uuid) implements CustomPayload {
|
||||
public static final CustomPayload.Id<HelloPacket> PACKET_ID = new CustomPayload.Id<>(VisualOverhaulCommon.HELLO_PACKET);
|
||||
public static final PacketCodec<PacketByteBuf, HelloPacket> codec = PacketCodec.of(HelloPacket::write, HelloPacket::read);
|
||||
|
||||
public static HelloPacket read(PacketByteBuf buf) {
|
||||
return new HelloPacket(buf.readUuid());
|
||||
}
|
||||
|
||||
public void write(PacketByteBuf buf) {
|
||||
buf.writeUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package eu.midnightdust.visualoverhaul.packet;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public record UpdateItemsPacket(Identifier blockTypeID, BlockPos pos, DefaultedList<ItemStack> inv) implements CustomPayload {
|
||||
public static final Id<UpdateItemsPacket> PACKET_ID = new Id<>(VisualOverhaulCommon.UPDATE_ITEMS_PACKET);
|
||||
public static final PacketCodec<RegistryByteBuf, UpdateItemsPacket> codec = PacketCodec.of(UpdateItemsPacket::write, UpdateItemsPacket::read);
|
||||
|
||||
public static UpdateItemsPacket read(RegistryByteBuf buf) {
|
||||
return new UpdateItemsPacket(buf.readIdentifier(), buf.readBlockPos(), (DefaultedList<ItemStack>) ItemStack.OPTIONAL_LIST_PACKET_CODEC.decode(buf));
|
||||
}
|
||||
|
||||
public void write(RegistryByteBuf buf) {
|
||||
buf.writeIdentifier(blockTypeID);
|
||||
buf.writeBlockPos(pos);
|
||||
ItemStack.OPTIONAL_LIST_PACKET_CODEC.encode(buf, this.inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.midnightdust.visualoverhaul.util;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -15,7 +16,7 @@ public class SoundTest {
|
||||
* {@link eu.midnightdust.visualoverhaul.mixin.MixinSoundSystem}
|
||||
*/
|
||||
public static Identifier getSound(BlockPos pos) {
|
||||
if (soundPos.containsKey(pos)) {
|
||||
if (VOConfig.jukebox_clientside && soundPos.containsKey(pos)) {
|
||||
return soundPos.get(pos);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package eu.midnightdust.visualoverhaul.util;
|
||||
|
||||
public class VOColorUtil {
|
||||
public static int convertRgbToArgb(int rgb) {
|
||||
int red = 0xFF & (rgb >> 16);
|
||||
int green = 0xFF & (rgb >> 8);
|
||||
int blue = 0xFF & (rgb);
|
||||
int alpha = 200; // Makes water bottles transparent, 255 would be opaque
|
||||
|
||||
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user