Skip to content

Commit

Permalink
Ported render types
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Dec 26, 2023
1 parent f5665dc commit b54bedf
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 77 deletions.
16 changes: 16 additions & 0 deletions common/src/main/java/glitchcore/util/RenderTypeHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*******************************************************************************
* Copyright 2023, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package glitchcore.util;

import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;

public class RenderTypeHelper
{
public static void setRenderType(Block block, RenderType type)
{
throw new UnsupportedOperationException();
}
}
8 changes: 8 additions & 0 deletions common/src/main/java/toughasnails/core/ToughAsNails.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
package toughasnails.core;

import glitchcore.event.EventManager;
import glitchcore.util.Environment;
import glitchcore.util.RegistryHelper;
import glitchcore.util.RenderTypeHelper;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.registries.Registries;
import toughasnails.init.*;
import toughasnails.temperature.TemperatureHandler;
import toughasnails.temperature.TemperatureOverlayRenderer;
import toughasnails.thirst.ThirstHandler;
import toughasnails.thirst.ThirstOverlayRenderer;

import static toughasnails.api.block.TANBlocks.RAIN_COLLECTOR;
import static toughasnails.api.block.TANBlocks.WATER_PURIFIER;

public class ToughAsNails
{
public static void init()
{
ModConfig.init();
ModTags.init();
addRegistrars();
addHandlers();
ModPackets.init();
Expand Down
21 changes: 21 additions & 0 deletions common/src/main/java/toughasnails/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
******************************************************************************/
package toughasnails.init;

import glitchcore.util.Environment;
import glitchcore.util.RenderTypeHelper;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
Expand All @@ -15,12 +18,30 @@

import java.util.function.BiConsumer;

import static toughasnails.api.block.TANBlocks.RAIN_COLLECTOR;
import static toughasnails.api.block.TANBlocks.WATER_PURIFIER;

public class ModBlocks
{
public static void registerBlocks(BiConsumer<ResourceLocation, Block> func)
{
TANBlocks.RAIN_COLLECTOR = register(func, "rain_collector", new RainCollectorBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).requiresCorrectToolForDrops().strength(2.0F).noOcclusion()));
TANBlocks.WATER_PURIFIER = register(func, "water_purifier", new WaterPurifierBlock(BlockBehaviour.Properties.of().requiresCorrectToolForDrops().strength(3.5F).noOcclusion()));

if (Environment.isClient())
{
registerRenderers();
}
}

private static void registerRenderers()
{
RenderType transparentRenderType = RenderType.cutoutMipped();
RenderType cutoutRenderType = RenderType.cutout();
RenderType translucentRenderType = RenderType.translucent();

RenderTypeHelper.setRenderType(RAIN_COLLECTOR, cutoutRenderType);
RenderTypeHelper.setRenderType(WATER_PURIFIER, cutoutRenderType);
}

private static Block register(BiConsumer<ResourceLocation, Block> func, String name, Block block)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright 2023, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package toughasnails.mixin.glitchcore.impl;

import glitchcore.util.RenderTypeHelper;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@Mixin(value = RenderTypeHelper.class, remap = false)
public class MixinRenderTypeHelper
{
@Overwrite
public static void setRenderType(Block block, RenderType type)
{
BlockRenderLayerMap.INSTANCE.putBlock(block, type);
}
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/toughasnails.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mixins": [
"glitchcore.impl.MixinEnvironment",
"glitchcore.impl.MixinPacketHandler",
"glitchcore.impl.MixinRenderTypeHelper",
"glitchcore.impl.MixinServerPlayer"
],
"client": [
Expand Down
2 changes: 1 addition & 1 deletion forge/src/main/java/glitchcore/forge/GlitchCoreForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void init()

}

public static void prepareEventHandlers(IEventBus modEventBus)
public static void prepareModEventHandlers(IEventBus modEventBus)
{
for (Class<? extends Event> eventClass : EventManager.getRequiredEvents())
{
Expand Down
26 changes: 0 additions & 26 deletions forge/src/main/java/toughasnails/core/ClientProxy.java

This file was deleted.

11 changes: 0 additions & 11 deletions forge/src/main/java/toughasnails/core/CommonProxy.java

This file was deleted.

36 changes: 2 additions & 34 deletions forge/src/main/java/toughasnails/core/ToughAsNailsForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,36 @@
******************************************************************************/
package toughasnails.core;

import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import glitchcore.forge.GlitchCoreForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import toughasnails.api.temperature.ITemperature;
import toughasnails.api.thirst.IThirst;
import toughasnails.init.*;

@Mod(value = ToughAsNailsForge.MOD_ID)
public class ToughAsNailsForge
{
public static final String MOD_ID = "toughasnails";

public static CommonProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new);

public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public ToughAsNailsForge()
{
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
bus.addListener(this::registerCapabilities);
bus.addListener(this::commonSetup);
bus.addListener(this::clientSetup);
bus.addListener(this::loadComplete);

ToughAsNails.init();
ModHandlers.init();
ModTags.init();
}

private void registerCapabilities(RegisterCapabilitiesEvent event)
{
event.register(IThirst.class);
event.register(ITemperature.class);
}

private void commonSetup(final FMLCommonSetupEvent event)
{
event.enqueueWork(() ->
{
});
}

private void clientSetup(final FMLClientSetupEvent event)
{
event.enqueueWork(() ->
{

});
GlitchCoreForge.prepareModEventHandlers(bus);
}

private void loadComplete(final FMLLoadCompleteEvent event)
{
event.enqueueWork(() ->
{
proxy.init();
ModCrafting.registerPotionRecipes();
ModCompatibility.init();
});
Expand Down
4 changes: 1 addition & 3 deletions forge/src/main/java/toughasnails/init/ModHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public static void init()
{
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();

MinecraftForge.EVENT_BUS.register(new ThirstHandler());
MinecraftForge.EVENT_BUS.register(new TemperatureHandler());

GlitchCoreForge.prepareEventHandlers(bus);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright 2023, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package toughasnails.mixin.glitchcore.impl;

import glitchcore.util.RenderTypeHelper;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@Mixin(value = RenderTypeHelper.class, remap = false)
public class MixinRenderTypeHelper
{
@Overwrite
public static void setRenderType(Block block, RenderType type)
{
ItemBlockRenderTypes.setRenderLayer(block, type);
}
}
5 changes: 3 additions & 2 deletions forge/src/main/resources/toughasnails.forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"compatibilityLevel": "JAVA_17",
"refmap": "toughasnails.refmap.json",
"mixins": [
"MixinTemperatureHelperImpl",
"glitchcore.impl.MixinEnvironment",
"glitchcore.impl.MixinPacketHandler",
"glitchcore.impl.MixinRecipeHelper",
"glitchcore.impl.MixinServerPlayer",
"MixinTemperatureHelperImpl"
"glitchcore.impl.MixinRenderTypeHelper",
"glitchcore.impl.MixinServerPlayer"
],
"client": [
"glitchcore.impl.client.MixinForgeGui"
Expand Down

0 comments on commit b54bedf

Please sign in to comment.