Skip to content

Commit

Permalink
Fixed #472
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael committed Jul 18, 2020
1 parent 1488552 commit 56b7add
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<TileEntity> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,15 +15,18 @@
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;
import net.minecraft.util.ResourceLocation;
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.*;
Expand All @@ -46,8 +50,6 @@ public static BuildingGadgets getInstance() {
return theMod;
}

private TemplateSave copyPasteSave;

public BuildingGadgets() {
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();

Expand All @@ -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<FMLClientSetupEvent>) 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static Minecraft getMc() {
return Minecraft.getInstance();
}

static FakeTERWorld getTileEntityWorld() {
public static FakeTERWorld getTileEntityWorld() {
return tileEntityWorld;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -74,9 +69,6 @@ public static IForgeRegistry<IUniqueObjectSerializer> getUniqueObjectSerializers

public static void setup() {
OurItems.setup();

DistExecutor.runWhenOn(Dist.CLIENT, () ->
() -> ClientRegistry.bindTileEntityRenderer(EffectBlockTileEntity.TYPE, EffectBlockTER::new));
}

public static void clientSetup() {
Expand Down

0 comments on commit 56b7add

Please sign in to comment.