From 5c9a8a804a9b636151b83abb25050ae4f40e69ce Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Sun, 27 Jun 2021 10:56:17 -0500 Subject: [PATCH] Implemented this SpecialRender system. --- .../common/ActuallyAdditions.java | 4 + .../special/RenderSpecial.java | 88 +++++++++++++++++++ .../special/SpecialRenderInit.java | 72 +++++++++++++++ .../special/ThreadSpecialFetcher.java | 40 +++++++++ 4 files changed, 204 insertions(+) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/special/RenderSpecial.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/special/SpecialRenderInit.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/special/ThreadSpecialFetcher.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java index 5b68fea82..3905cf031 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java @@ -7,6 +7,7 @@ import de.ellpeck.actuallyadditions.common.config.Config; import de.ellpeck.actuallyadditions.common.container.ActuallyContainers; import de.ellpeck.actuallyadditions.common.items.ActuallyItems; import de.ellpeck.actuallyadditions.common.tiles.ActuallyTiles; +import de.ellpeck.actuallyadditions.special.SpecialRenderInit; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.command.Commands; @@ -53,6 +54,7 @@ public class ActuallyAdditions { eventBus.addListener(this::clientSetup); MinecraftForge.EVENT_BUS.addListener(this::serverLoad); + MinecraftForge.EVENT_BUS.addListener(SpecialRenderInit::onPlayerRender); MinecraftForge.EVENT_BUS.register(this); } @@ -70,6 +72,8 @@ public class ActuallyAdditions { RenderTypeLookup.setRenderLayer(ActuallyBlocks.CRYSTAL_CLUSTER_DIAMATINE.get(), RenderType.getTranslucent()); RenderTypeLookup.setRenderLayer(ActuallyBlocks.CRYSTAL_CLUSTER_EMERADIC.get(), RenderType.getTranslucent()); RenderTypeLookup.setRenderLayer(ActuallyBlocks.GREENHOUSE_GLASS.get(), RenderType.getCutout()); + + SpecialRenderInit.fetch(); } private void serverLoad(FMLServerStartingEvent event) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/special/RenderSpecial.java b/src/main/java/de/ellpeck/actuallyadditions/special/RenderSpecial.java new file mode 100644 index 000000000..310352c4e --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/special/RenderSpecial.java @@ -0,0 +1,88 @@ +/* + * This file ("RenderSpecial.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2017 Ellpeck + */ + +package de.ellpeck.actuallyadditions.special; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.model.ItemCameraTransforms; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerModelPart; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Util; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3f; + +public class RenderSpecial { + + private final ItemStack theThingToRender; + + public RenderSpecial(ItemStack stack) { + this.theThingToRender = stack; + } + + public void render(MatrixStack matrixStack, IRenderTypeBuffer buffer, int combinedLight, PlayerEntity player, float partialTicks) { + if (this.theThingToRender.isEmpty() || player.isInvisible() || !player.isWearing(PlayerModelPart.CAPE) || player.isElytraFlying()) { + return; + } + + matrixStack.push(); + + Vector3d currentPos = Minecraft.getInstance().player.getEyePosition(partialTicks); + Vector3d playerPos = player.getEyePosition(partialTicks); + matrixStack.translate(playerPos.x - currentPos.x, playerPos.y - currentPos.y, playerPos.z - currentPos.z); + matrixStack.translate(0D, 2.575D - (player.isSneaking() + ? 0.125D + : 0D), 0D); + + + matrixStack.push(); + + boolean isBlock = this.theThingToRender.getItem() instanceof BlockItem; + if (isBlock) { + matrixStack.translate(0D, -0.1875D, 0D); + } + matrixStack.rotate(Vector3f.ZP.rotationDegrees(180)); + + float size = isBlock + ? 0.5F + : 0.4F; + matrixStack.scale(size, size, size); + + //Make the floaty stuff look nice using sine waves \o/ -xdjackiexd + //Peck edit: What do you mean by "nice" you jackass? >_> + double boop = Util.milliTime() / 1000D; + matrixStack.translate(0D, Math.sin(boop % (2 * Math.PI)) * 0.25, 0D); + matrixStack.rotate(Vector3f.YP.rotationDegrees((float) (boop * 40D % 360))); + + GlStateManager.disableLighting(); + matrixStack.push(); + + if (!isBlock) { + matrixStack.translate(0D, 0.5D, 0D); + } + matrixStack.rotate(Vector3f.XN.rotationDegrees(180F)); + Minecraft.getInstance().getItemRenderer().renderItem(theThingToRender, ItemCameraTransforms.TransformType.FIXED, combinedLight, OverlayTexture.NO_OVERLAY, matrixStack, buffer); + matrixStack.pop(); + + GlStateManager.enableLighting(); + + matrixStack.pop(); + + + matrixStack.pop(); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/special/SpecialRenderInit.java b/src/main/java/de/ellpeck/actuallyadditions/special/SpecialRenderInit.java new file mode 100644 index 000000000..9bd5d4cdf --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/special/SpecialRenderInit.java @@ -0,0 +1,72 @@ +/* + * This file ("SpecialRenderInit.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2017 Ellpeck + */ + +package de.ellpeck.actuallyadditions.special; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.RenderPlayerEvent; +import net.minecraftforge.eventbus.api.EventPriority; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Properties; + +public class SpecialRenderInit { + + public static final HashMap SPECIAL_LIST = new HashMap<>(); + + public static void fetch() { + new ThreadSpecialFetcher(); + } + + // TODO: [port][note] ensure that this still works with the special people stuff + public static void parse(Properties properties) { + for (String key : properties.stringPropertyNames()) { + ResourceLocation resLoc = new ResourceLocation(properties.getProperty(key)); + ItemStack stack = findItem(resLoc); + + if (!stack.isEmpty()) { + SPECIAL_LIST.put(key.toLowerCase(Locale.ROOT), new RenderSpecial(stack)); + } + } + } + + private static ItemStack findItem(ResourceLocation resLoc) { + if (ForgeRegistries.ITEMS.containsKey(resLoc)) { + Item item = ForgeRegistries.ITEMS.getValue(resLoc); + if (item != null) { + return new ItemStack(item); + } + } else if (ForgeRegistries.BLOCKS.containsKey(resLoc)) { + Block block = ForgeRegistries.BLOCKS.getValue(resLoc); + if (block != null) { + return new ItemStack(block); + } + } + return ItemStack.EMPTY; + } + + public static void onPlayerRender(RenderPlayerEvent.Pre event) { + if (event.getPlayer() != null) { + String name = event.getPlayer().getName().getString(); + String lower = name.toLowerCase(Locale.ROOT); // TODO: Maybe convert the special people list to UUIDs? + RenderSpecial render = SPECIAL_LIST.get(lower); + if (render != null) { + render.render(event.getMatrixStack(), event.getBuffers(), event.getLight(), event.getPlayer(), event.getPartialRenderTick()); + } + } + } + +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/special/ThreadSpecialFetcher.java b/src/main/java/de/ellpeck/actuallyadditions/special/ThreadSpecialFetcher.java new file mode 100644 index 000000000..515411537 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/special/ThreadSpecialFetcher.java @@ -0,0 +1,40 @@ +/* + * This file ("ThreadSpecialFetcher.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2017 Ellpeck + */ + +package de.ellpeck.actuallyadditions.special; + +import de.ellpeck.actuallyadditions.common.ActuallyAdditions; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Properties; + +public class ThreadSpecialFetcher extends Thread { + + public ThreadSpecialFetcher() { + this.setName(ActuallyAdditions.MOD_ID + " Special Fetcher"); + this.setDaemon(true); + this.start(); + } + + @Override + public void run() { + ActuallyAdditions.LOGGER.info("Fetching Special People Stuff..."); + try { + URL url = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/clean-start/specialPeopleStuff.properties"); + Properties specialProperties = new Properties(); + specialProperties.load(new InputStreamReader(url.openStream())); + SpecialRenderInit.parse(specialProperties); + + ActuallyAdditions.LOGGER.info("Fetching Special People Stuff done!"); + } catch (Exception e) { + ActuallyAdditions.LOGGER.error("Fetching Special People Stuff failed! (You can ignore this error technically.)", e); + } + } +}