diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-11-23 11:35:00 -0800 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-11-23 11:35:00 -0800 |
commit | 45ba481ef75db5e0f9e09b8695da4a911da16fdb (patch) | |
tree | f97188d054901e8c64497df46dff400eab8ea1b8 /src/main/java/com/anthonyhilyard | |
parent | 1a86b08671478a158a7561bf6f32da760acc490c (diff) | |
download | Iceberg-45ba481ef75db5e0f9e09b8695da4a911da16fdb.tar.gz Iceberg-45ba481ef75db5e0f9e09b8695da4a911da16fdb.tar.bz2 Iceberg-45ba481ef75db5e0f9e09b8695da4a911da16fdb.zip |
Initial 1.18 port.
Diffstat (limited to 'src/main/java/com/anthonyhilyard')
6 files changed, 182 insertions, 35 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java index 5e63b2d..9074aa3 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java +++ b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java @@ -1,7 +1,5 @@ package com.anthonyhilyard.iceberg; -import com.anthonyhilyard.iceberg.network.IcebergNetworkProtocol; - import net.fabricmc.api.ClientModInitializer; public class IcebergClient implements ClientModInitializer @@ -9,6 +7,22 @@ public class IcebergClient implements ClientModInitializer @Override public void onInitializeClient() { - IcebergNetworkProtocol.registerHandlers(); + // Event testing. + // CriterionCallback.EVENT.register((player, advancement, criterion) -> { Loader.LOGGER.info("CriterionCallback: {}, {}, {}", player.getName().getString(), advancement.getId().toString(), criterion); }); + // EntityFluidEvents.ENTERED.register((entity, fluid) -> { Loader.LOGGER.info("EntityFluidEvents.ENTERED: {}, {}", entity.getName().getString(), Registry.FLUID.getKey(fluid).toString()); }); + // EntityFluidEvents.EXITED.register((entity, fluid) -> { Loader.LOGGER.info("EntityFluidEvents.EXITED: {}, {}", entity.getName().getString(), Registry.FLUID.getKey(fluid).toString()); }); + // NewItemPickupCallback.EVENT.register((uuid, itemStack) -> { Loader.LOGGER.info("NewItemPickupCallback: {}, {}", uuid.toString(), itemStack.getDisplayName().getString()); }); + // RenderTickEvents.START.register((timer) -> { Loader.LOGGER.info("RenderTickEvents.START: {}", timer); }); + // RenderTooltipEvents.PRE.register((stack, components, poseStack, x, y, screenWidth, screenHeight, maxWidth, font, comparison) -> { + // Loader.LOGGER.info("RenderTooltipEvents.PRE: {}, {}, {}, {}, {}, {}, {}, {}, {}, {}", stack.getDisplayName().getString(), components.stream().map(Object::toString).collect(Collectors.joining()), poseStack, x, y, screenWidth, screenHeight, maxWidth, font, comparison); + // return InteractionResult.SUCCESS; + // }); + // RenderTooltipEvents.COLOR.register((stack, components, poseStack, x, y, font, background, borderStart, borderEnd, comparison) -> { + // Loader.LOGGER.info("RenderTooltipEvents.COLOR: {}, {}, {}, {}, {}, {}, {}, {}, {}, {}", stack.getDisplayName().getString(), components.stream().map(Object::toString).collect(Collectors.joining()), poseStack, x, y, font, borderStart, borderEnd, comparison); + // return null; + // }); + // RenderTooltipEvents.POST.register((stack, components, poseStack, x, y, font, width, height, comparison) -> { + // Loader.LOGGER.info("RenderTooltipEvents.POST: {}, {}, {}, {}, {}, {}, {}, {}, {}", stack.getDisplayName().getString(), components.stream().map(Object::toString).collect(Collectors.joining()), poseStack, x, y, font, width, height, comparison); + // }); } } diff --git a/src/main/java/com/anthonyhilyard/iceberg/Loader.java b/src/main/java/com/anthonyhilyard/iceberg/Loader.java index d8c3af5..b8ad701 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/Loader.java +++ b/src/main/java/com/anthonyhilyard/iceberg/Loader.java @@ -14,29 +14,4 @@ public class Loader implements ModInitializer public void onInitialize() { } - - // Event testing. - // - // @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.FORGE) - // public static class AdvancementEvents - // { - // @SubscribeEvent - // public static void onCriterion(final CriterionEvent event) - // { - // LOGGER.info("{} gained {} for {}!", event.getPlayer().getName().getString(), event.getCriterionKey(), event.getAdvancement().getId().toString()); - // } - - // @SubscribeEvent - // public static void onFluidEntered(final EntityFluidEvent.Entered event) - // { - // LOGGER.info("{} entered {}!", event.getEntity().getName().getString(), event.getFluid().getRegistryName().toString()); - // } - - // @SubscribeEvent - // public static void onFluidExited(final EntityFluidEvent.Exited event) - // { - // LOGGER.info("{} exited {}!", event.getEntity().getName().getString(), event.getFluid().getRegistryName().toString()); - // } - // } - }
\ No newline at end of file diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java index 98c8a27..06e0e90 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java @@ -114,9 +114,12 @@ public class ScreenMixin extends AbstractContainerEventHandler { // Do colors now, sure why not. ColorResult result = RenderTooltipEvents.COLOR.invoker().onColor(tooltipStack, components, poseStack, x, y, font, background, borderStart, borderEnd, false); - background = result.background(); - borderStart = result.borderStart(); - borderEnd = result.borderEnd(); + if (result != null) + { + background = result.background(); + borderStart = result.borderStart(); + borderEnd = result.borderEnd(); + } Screen.fillGradient(matrix4f, bufferBuilder, left - 3, top - 4, left + width + 3, top - 3, zIndex, background, background); Screen.fillGradient(matrix4f, bufferBuilder, left - 3, top + height + 3, left + width + 3, top + height + 4, zIndex, background, background); diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java b/src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java new file mode 100644 index 0000000..127fc60 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java @@ -0,0 +1,151 @@ +package com.anthonyhilyard.iceberg.util; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.PackResources; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.metadata.MetadataSectionSerializer; + +/** + * DynamicResourcePack allows resources that are defined arbitrarily to do cool things with resources. + * For example, resources that change in response to game state, resource proxies, or resources downloaded from the internet. + */ +public class DynamicResourcePack implements PackResources +{ + private record DynamicResourceKey(String type, String namespace, String path) {} + + private final String packName; + private Map<DynamicResourceKey, Supplier<InputStream>> dynamicResourceMap = new HashMap<DynamicResourceKey, Supplier<InputStream>>(); + + public DynamicResourcePack(String packName) + { + this.packName = packName; + } + + public void clear() + { + dynamicResourceMap.clear(); + } + + public boolean removeResource(PackType type, ResourceLocation location) + { + DynamicResourceKey key = new DynamicResourceKey(type.getDirectory(), location.getNamespace(), location.getPath()); + if (dynamicResourceMap.containsKey(key)) + { + dynamicResourceMap.remove(key); + return true; + } + else + { + return false; + } + } + + public boolean registerResource(PackType type, ResourceLocation location, Supplier<InputStream> resourceSupplier) + { + return register(type.getDirectory(), location.getNamespace(), location.getPath(), resourceSupplier); + } + + public boolean registerRootResource(String path, Supplier<InputStream> resourceSupplier) + { + return register("root", "", path, resourceSupplier); + } + + private boolean register(String directory, String namespace, String path, Supplier<InputStream> resourceSupplier) + { + DynamicResourceKey key = new DynamicResourceKey(directory, namespace, path); + if (!dynamicResourceMap.containsKey(key)) + { + dynamicResourceMap.put(key, resourceSupplier); + return true; + } + return false; + } + + @Override + public InputStream getRootResource(String path) throws IOException + { + return getResource("root", "", path); + } + + @Override + public InputStream getResource(PackType type, ResourceLocation location) throws IOException + { + return getResource(type.getDirectory(), location.getNamespace(), location.getPath()); + } + + private InputStream getResource(String directory, String namespace, String path) throws IOException + { + DynamicResourceKey key = new DynamicResourceKey(directory, namespace, path); + if (dynamicResourceMap.containsKey(key)) + { + return dynamicResourceMap.get(key).get(); + } + else + { + throw new FileNotFoundException("Can't find dynamic resource " + path + ". Please ensure it has been registered."); + } + } + + @Override + public Collection<ResourceLocation> getResources(PackType type, String namespace, String path, int maxDepth, Predicate<String> filter) + { + return dynamicResourceMap.entrySet().stream() + .filter(entry -> entry.getKey().namespace.contentEquals(namespace)) + .filter(entry -> entry.getKey().path.startsWith(path)) + .filter(entry -> entry.getKey().type.contentEquals(type.getDirectory())) + .filter(entry -> filter.test(entry.getKey().path)) + .map(entry -> new ResourceLocation(namespace, entry.getKey().path)) + .collect(Collectors.toList()); + } + + @Override + public boolean hasResource(PackType type, ResourceLocation location) + { + return dynamicResourceMap.containsKey(new DynamicResourceKey(type.getDirectory(), location.getNamespace(), location.getPath())); + } + + @Override + public Set<String> getNamespaces(PackType type) + { + Set<String> namespaces = new HashSet<>(); + for (DynamicResourceKey key : dynamicResourceMap.keySet()) + { + if (type.getDirectory().contentEquals(key.type)) + { + namespaces.add(key.namespace); + } + } + return namespaces; + } + + @Override + public <T> T getMetadataSection(MetadataSectionSerializer<T> p_10291_) throws IOException + { + // Does nothing for now. + // TODO: Add metadata? Probably not needed right? + return null; + } + + @Override + public String getName() + { + return packName; + } + + @Override + public void close() + { + } +} diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java index 04645db..5fcaf41 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java @@ -27,10 +27,12 @@ public class Selectors public static boolean itemMatches(ItemStack item, String selector) { String itemResourceLocation = Registry.ITEM.getKey(item.getItem()).toString(); + // Item ID if (selector.equals(itemResourceLocation) || selector.equals(itemResourceLocation.replace("minecraft:", ""))) { return true; } + // Item name color else if (selector.startsWith("#")) { TextColor entryColor = TextColor.parseColor(selector); @@ -39,6 +41,7 @@ public class Selectors return true; } } + // Vanilla rarity else if (selector.startsWith("!")) { if (item.getRarity() == rarities.get(selector.substring(1))) @@ -46,6 +49,7 @@ public class Selectors return true; } } + // Mod ID else if (selector.startsWith("@")) { if (itemResourceLocation.startsWith(selector.substring(1) + ":")) @@ -53,6 +57,7 @@ public class Selectors return true; } } + // Item tag else if (selector.startsWith("$")) { if (ItemTags.getAllTags().getTagOrEmpty(new ResourceLocation(selector.substring(1))).getValues().contains(item.getItem())) @@ -60,6 +65,7 @@ public class Selectors return true; } } + // Item display name else if (selector.startsWith("%")) { if (item.getDisplayName().getString().contains(selector.substring(1))) @@ -67,6 +73,7 @@ public class Selectors return true; } } + // Tooltip text else if (selector.startsWith("^")) { Minecraft mc = Minecraft.getInstance(); diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java index c55c5c7..27d7c87 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java @@ -20,7 +20,6 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.Rect2i; import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.client.renderer.texture.TextureManager; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; @@ -36,7 +35,6 @@ public class Tooltips { private static boolean initialized = false; private static ItemRenderer itemRenderer = null; - private static TextureManager textureManager = null; public static class TooltipInfo { @@ -125,7 +123,6 @@ public class Tooltips private static void init(Minecraft minecraft) { itemRenderer = minecraft.getItemRenderer(); - textureManager = minecraft.getTextureManager(); initialized = true; } @@ -271,7 +268,7 @@ public class Tooltips for (int i = 0; i < info.getLines().size(); ++i) { clientTooltipComponent3 = (ClientTooltipComponent)info.getLines().get(i); - clientTooltipComponent3.renderImage(info.getFont(), tooltipX, v, poseStack, itemRenderer, 400, textureManager); + clientTooltipComponent3.renderImage(info.getFont(), tooltipX, v, poseStack, itemRenderer, 400); v += clientTooltipComponent3.getHeight() + (i == 0 ? 2 : 0); } |