From 56b7addbc07d809b28b0a82ca8392148860eed22 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 18 Jul 2020 10:16:08 +0100 Subject: [PATCH] Fixed #472 --- .../client/renderer/EffectBlockTER.java | 30 ++++++++++++++++--- .../common/BuildingGadgets.java | 22 ++++++++------ .../items/gadgets/renderers/BaseRenderer.java | 2 +- .../common/registry/Registries.java | 8 ----- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/direwolf20/buildinggadgets/client/renderer/EffectBlockTER.java b/src/main/java/com/direwolf20/buildinggadgets/client/renderer/EffectBlockTER.java index 533e23c3e..d477f4415 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/client/renderer/EffectBlockTER.java +++ b/src/main/java/com/direwolf20/buildinggadgets/client/renderer/EffectBlockTER.java @@ -1,7 +1,9 @@ package com.direwolf20.buildinggadgets.client.renderer; +import com.direwolf20.buildinggadgets.common.BuildingGadgets; import com.direwolf20.buildinggadgets.common.blocks.EffectBlock; import com.direwolf20.buildinggadgets.common.building.BlockData; +import com.direwolf20.buildinggadgets.common.items.gadgets.renderers.BaseRenderer; import com.direwolf20.buildinggadgets.common.registry.OurBlocks; import com.direwolf20.buildinggadgets.common.tiles.EffectBlockTileEntity; import com.mojang.blaze3d.matrix.MatrixStack; @@ -11,11 +13,15 @@ import net.minecraft.client.renderer.BlockRendererDispatcher; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraftforge.client.model.data.EmptyModelData; @@ -68,11 +74,27 @@ public void render(EffectBlockTileEntity tile, float partialTicks, MatrixStack s renderBlockState = OurBlocks.constructionBlockDense.getDefaultState(); builder = buffer2.getBuffer(MyRenderType.RenderBlock); - IBakedModel ibakedmodel = dispatcher.getModelForState(renderBlockState); - for (Direction direction : Direction.values()) { - renderModelBrightnessColorQuads(stack.getLast(), builder, f, f1, f2, 1f, ibakedmodel.getQuads(renderBlockState, direction, new Random(MathHelper.getPositionRandom(tile.getPos())), EmptyModelData.INSTANCE), 15728640, 655360); + if (!renderData.getState().hasTileEntity()) { + IBakedModel ibakedmodel = dispatcher.getModelForState(renderBlockState); + for (Direction direction : Direction.values()) { + renderModelBrightnessColorQuads(stack.getLast(), builder, f, f1, f2, 1f, ibakedmodel.getQuads(renderBlockState, direction, new Random(MathHelper.getPositionRandom(tile.getPos())), EmptyModelData.INSTANCE), 15728640, 655360); + } + renderModelBrightnessColorQuads(stack.getLast(), builder, f, f1, f2, 1f, ibakedmodel.getQuads(renderBlockState, null, new Random(MathHelper.getPositionRandom(tile.getPos())), EmptyModelData.INSTANCE), 15728640, 655360); + } else { + TileEntity te = BaseRenderer.getTileEntityWorld().getTE(renderBlockState, tile.getWorld()); + TileEntityRenderer teRender = BaseRenderer.getTileEntityWorld().getTER(renderBlockState, tile.getWorld()); + + if (teRender != null) { + te.setPos(tile.getPos()); + stack.push(); + try { + teRender.render(te, partialTicks, stack, buffer, 15728880, OverlayTexture.NO_OVERLAY); + } catch (Exception e) { + BuildingGadgets.LOG.warn("TER Exception with block type: " + renderBlockState); + } + stack.pop(); + } } - renderModelBrightnessColorQuads(stack.getLast(), builder, f, f1, f2, 1f, ibakedmodel.getQuads(renderBlockState, null, new Random(MathHelper.getPositionRandom(tile.getPos())), EmptyModelData.INSTANCE), 15728640, 655360); stack.pop(); stack.push(); diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/BuildingGadgets.java b/src/main/java/com/direwolf20/buildinggadgets/common/BuildingGadgets.java index 377757d16..1a642b298 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/BuildingGadgets.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/BuildingGadgets.java @@ -1,6 +1,7 @@ package com.direwolf20.buildinggadgets.common; import com.direwolf20.buildinggadgets.client.ClientProxy; +import com.direwolf20.buildinggadgets.client.renderer.EffectBlockTER; import com.direwolf20.buildinggadgets.client.screen.GuiMod; import com.direwolf20.buildinggadgets.common.capability.CapabilityBlockProvider; import com.direwolf20.buildinggadgets.common.capability.CapabilityTemplate; @@ -14,6 +15,7 @@ import com.direwolf20.buildinggadgets.common.registry.Registries; import com.direwolf20.buildinggadgets.common.save.SaveManager; import com.direwolf20.buildinggadgets.common.save.TemplateSave; +import com.direwolf20.buildinggadgets.common.tiles.EffectBlockTileEntity; import com.direwolf20.buildinggadgets.common.util.ref.Reference; import net.minecraft.command.Commands; import net.minecraft.item.crafting.IRecipeSerializer; @@ -21,8 +23,10 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.*; +import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig.Type; import net.minecraftforge.fml.event.lifecycle.*; @@ -46,8 +50,6 @@ public static BuildingGadgets getInstance() { return theMod; } - private TemplateSave copyPasteSave; - public BuildingGadgets() { IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); @@ -58,23 +60,25 @@ public BuildingGadgets() { MinecraftForge.EVENT_BUS.addListener(this::serverLoad); MinecraftForge.EVENT_BUS.addListener(this::serverLoaded); MinecraftForge.EVENT_BUS.addListener(this::serverStopped); + eventBus.addListener(this::registerRegistries); eventBus.addListener(this::setup); + eventBus.addListener(this::clientSetup); eventBus.addListener(this::loadComplete); eventBus.addListener(this::handleIMC); - eventBus.addGenericListener(IRecipeSerializer.class, this::onRecipeRegister); + eventBus.addGenericListener(IRecipeSerializer.class, this::onRecipeRegister); eventBus.addListener(this::onEnqueueIMC); - // Client only registering - DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { - eventBus.addListener((Consumer) event -> ClientProxy.clientSetup(eventBus)); - ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> GuiMod::openScreen); - }); - Registries.setup(); } + private void clientSetup(final FMLClientSetupEvent event) { + ClientRegistry.bindTileEntityRenderer(EffectBlockTileEntity.TYPE, EffectBlockTER::new); + ClientProxy.clientSetup(FMLJavaModLoadingContext.get().getModEventBus()); + ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> GuiMod::openScreen); + } + private void setup(final FMLCommonSetupEvent event) { theMod = (BuildingGadgets) ModLoadingContext.get().getActiveContainer().getMod(); CapabilityBlockProvider.register(); diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/items/gadgets/renderers/BaseRenderer.java b/src/main/java/com/direwolf20/buildinggadgets/common/items/gadgets/renderers/BaseRenderer.java index 6bed5cac9..9873facc4 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/items/gadgets/renderers/BaseRenderer.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/items/gadgets/renderers/BaseRenderer.java @@ -187,7 +187,7 @@ static Minecraft getMc() { return Minecraft.getInstance(); } - static FakeTERWorld getTileEntityWorld() { + public static FakeTERWorld getTileEntityWorld() { return tileEntityWorld; } diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/registry/Registries.java b/src/main/java/com/direwolf20/buildinggadgets/common/registry/Registries.java index 5cad8ca92..09446be8c 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/registry/Registries.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/registry/Registries.java @@ -1,6 +1,5 @@ package com.direwolf20.buildinggadgets.common.registry; -import com.direwolf20.buildinggadgets.client.renderer.EffectBlockTER; import com.direwolf20.buildinggadgets.common.BuildingGadgets; import com.direwolf20.buildinggadgets.common.building.tilesupport.ITileDataFactory; import com.direwolf20.buildinggadgets.common.building.tilesupport.ITileDataSerializer; @@ -9,20 +8,16 @@ import com.direwolf20.buildinggadgets.common.inventory.handle.IObjectHandle; import com.direwolf20.buildinggadgets.common.inventory.materials.objects.IUniqueObjectSerializer; import com.direwolf20.buildinggadgets.common.template.SerialisationSupport; -import com.direwolf20.buildinggadgets.common.tiles.EffectBlockTileEntity; import com.direwolf20.buildinggadgets.common.util.ref.NBTKeys; import com.direwolf20.buildinggadgets.common.util.ref.Reference; import com.google.common.base.Preconditions; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.InterModComms; -import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; import net.minecraftforge.registries.IForgeRegistry; @@ -74,9 +69,6 @@ public static IForgeRegistry getUniqueObjectSerializers public static void setup() { OurItems.setup(); - - DistExecutor.runWhenOn(Dist.CLIENT, () -> - () -> ClientRegistry.bindTileEntityRenderer(EffectBlockTileEntity.TYPE, EffectBlockTER::new)); } public static void clientSetup() {