Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at merging in BlockRenderer #29

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
// Add your dependencies here

dependencies {
api("com.github.GTNewHorizons:GTNHLib:0.3.2:dev")
runtimeOnly("com.github.GTNewHorizons:NotEnoughItems:2.6.14-GTNH:dev")
api("com.github.GTNewHorizons:GTNHLib:0.4.0:dev")
// Now a hard dep for the NEI Handlers
api("com.github.GTNewHorizons:NotEnoughItems:2.6.22-GTNH:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughEnergistics:1.6.0:dev")

testImplementation(platform('org.junit:junit-bom:5.9.2'))
testImplementation('org.junit.jupiter:junit-jupiter')


// Temporary
api("com.github.GTNewHorizons:GT5-Unofficial:5.09.48.150:dev") {
exclude group:"com.github.GTNewHorizons", module:"StructureLib"
}
runtimeOnlyNonPublishable("com.github.GTNewHorizons:StructureCompat:0.6.3:dev") {
exclude group:"com.github.GTNewHorizons", module:"StructureLib"
}

compileOnly('org.jetbrains:annotations:24.0.1')
compileOnly("org.projectlombok:lombok:1.18.22") {transitive = false }
annotationProcessor("org.projectlombok:lombok:1.18.22")

runtimeOnlyNonPublishable(rfg.deobf("CoreTweaks:CoreTweaks:0.3.3.2"))
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ enableGenericInjection = true
# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
generateGradleTokenClass =
generateGradleTokenClass = com.gtnewhorizon.structurelib.Tags

# Name of the token containing the project's current version to generate/replace.
gradleTokenVersion = GRADLETOKEN_VERSION
gradleTokenVersion = VERSION

# [DEPRECATED] Mod ID replacement token.
gradleTokenModId =
Expand All @@ -70,7 +70,7 @@ gradleTokenGroupName =
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...]).
# Leave these properties empty to skip individual token replacements.
replaceGradleTokenInFile = StructureLib.java
replaceGradleTokenInFile =

# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
Expand All @@ -80,13 +80,13 @@ apiPackage =
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# There can be multiple files in a space-separated list.
# Example value: mymodid_at.cfg nei_at.cfg
accessTransformersFile =
accessTransformersFile = structurelib_at.cfg

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = true

# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false
usesMixinDebug = true

# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =
Expand Down
18 changes: 18 additions & 0 deletions repositories.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
// Add any additional repositiroes for your dependencies here

repositories {
exclusiveContent {
forRepository {
ivy {
name = 'CoreTweaks releases'
url = 'https://github.com/makamys/CoreTweaks/releases/download/'
patternLayout {
artifact '[revision]/[module]-1.7.10-[revision]+nomixin(-[classifier])(.[ext])'
}
metadataSources {
artifact()
}
}
}
filter {
includeGroup('CoreTweaks')
}
}
mavenLocal()
}
86 changes: 86 additions & 0 deletions src/main/java/com/gtnewhorizon/structurelib/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
Expand All @@ -24,28 +25,45 @@
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.world.WorldEvent;

import org.lwjgl.opengl.GL11;

import com.gtnewhorizon.structurelib.client.nei.IMCForNEI;
import com.gtnewhorizon.structurelib.client.nei.InputHandler;
import com.gtnewhorizon.structurelib.client.renderer.RenderStructureGlobal;
import com.gtnewhorizon.structurelib.client.world.StructureWorld;
import com.gtnewhorizon.structurelib.entity.fx.WeightlessParticleFX;
import com.gtnewhorizon.structurelib.net.SetChannelDataMessage;

import codechicken.nei.guihook.GuiContainerManager;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;

public class ClientProxy extends CommonProxy {

// Structure Renderer
private static final Minecraft minecraft = Minecraft.getMinecraft();
private static StructureWorld structureWorld = null;
private static final ThreadLocal<RenderStructureGlobal> renderStructureGlobal = ThreadLocal
.withInitial(RenderStructureGlobal::new);

// End Structure Renderer
private static final short[] RGBA_NO_TINT = { 255, 255, 255, 255 };
private static final short[] RGBA_RED_TINT = { 255, 128, 128, 0 };
private static final Map<HintParticleInfo, HintGroup> allHints = new HashMap<>();

/**
* All batches of hints.
*/
Expand Down Expand Up @@ -81,6 +99,14 @@ public class ClientProxy extends CommonProxy {
*/
private static final Map<Object, Long> localThrottleMap = new HashMap<>();

public static StructureWorld getStructureWorld() {
return structureWorld;
}

public static void setStructureWorld(StructureWorld structureWorld) {
ClientProxy.structureWorld = structureWorld;
}

@Override
public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) {
ensureHinting();
Expand Down Expand Up @@ -242,8 +268,44 @@ public void uploadChannels(ItemStack trigger) {

@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
FMLCommonHandler.instance().bus().register(new FMLEventHandler());
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
GuiContainerManager.addInputHandler(new InputHandler());
GuiContainerManager.addTooltipHandler(new InputHandler());
}

@Override
public void init(FMLInitializationEvent e) {
super.init(e);
IMCForNEI.IMCSender();
}

@Override
public void postInit(FMLPostInitializationEvent e) {
super.postInit(e);
MinecraftForge.EVENT_BUS.register(new EventHandler());
}

private static ForgeDirection getOrientation(EntityPlayer player) {
if (player.rotationPitch > 45) {
return ForgeDirection.DOWN;
} else if (player.rotationPitch < -45) {
return ForgeDirection.UP;
} else {
switch (MathHelper.floor_double(player.rotationYaw / 90.0 + 0.5) & 3) {
case 0:
return ForgeDirection.SOUTH;
case 1:
return ForgeDirection.WEST;
case 2:
return ForgeDirection.NORTH;
case 3:
return ForgeDirection.EAST;
}
}

return ForgeDirection.UNKNOWN;
}

static void markTextureUsed(IIcon icon) {
Expand Down Expand Up @@ -503,6 +565,29 @@ public void onWorldLoad(WorldEvent.Load e) {

@SubscribeEvent
public void onRenderWorldLast(RenderWorldLastEvent e) {
renderParticlePreview(e);
renderNewPreview(e);
}

private void renderNewPreview(RenderWorldLastEvent e) {
EntityPlayerSP player = minecraft.thePlayer;
if (player == null || structureWorld == null || !structureWorld.isRendering()) return;

final RenderStructureGlobal renderStructureGlobal = ClientProxy.renderStructureGlobal.get();
renderStructureGlobal.setPlayerPosition(
player.lastTickPosX + (player.posX - player.lastTickPosX) * e.partialTicks,
player.lastTickPosY + (player.posY - player.lastTickPosY) * e.partialTicks,
player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * e.partialTicks);
renderStructureGlobal.setOrientation(getOrientation(player));
renderStructureGlobal.setRotationRender(MathHelper.floor_double(player.rotationYaw / 90) & 3);

minecraft.mcProfiler.startSection("structlibRenderPreview");
renderStructureGlobal.render(structureWorld);

minecraft.mcProfiler.endSection();
}

private void renderParticlePreview(RenderWorldLastEvent e) {
if (allHintsForRender.isEmpty()) return;

// seriously, I'm not a OpenGL expert, so I'm probably doing a lot of very stupid stuff here.
Expand Down Expand Up @@ -571,4 +656,5 @@ public void onRenderWorldLast(RenderWorldLastEvent e) {
p.endSection();
}
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/gtnewhorizon/structurelib/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.gtnewhorizon.structurelib.net.ErrorHintParticleMessage;
import com.gtnewhorizon.structurelib.net.UpdateHintParticleMessage;

import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

public class CommonProxy {
Expand Down Expand Up @@ -55,6 +57,10 @@ public void endHinting(World w) {}

public void preInit(FMLPreInitializationEvent e) {}

public void init(FMLInitializationEvent e) {}

public void postInit(FMLPostInitializationEvent e) {}

public long getOverworldTime() {
return MinecraftServer.getServer().getEntityWorld().getTotalWorldTime();
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/gtnewhorizon/structurelib/EventHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.gtnewhorizon.structurelib;

import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
import com.gtnewhorizon.structurelib.client.nei.GUI_MultiblockHandler;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import com.gtnewhorizon.structurelib.util.PositionedIStructureElement;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class EventHandler {

@SubscribeEvent
public void OnStructureEvent(StructureEvent.StructureElementVisitedEvent event) {
GUI_MultiblockHandler.structureElements.add(
new PositionedIStructureElement(
event.getX(),
event.getY(),
event.getZ(),
(IStructureElement<IConstructable>) event.getElement()));
}
}
23 changes: 21 additions & 2 deletions src/main/java/com/gtnewhorizon/structurelib/StructureLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
Expand All @@ -37,8 +39,8 @@
*/
@Mod(
modid = StructureLibAPI.MOD_ID,
name = "StructureLib",
version = "GRADLETOKEN_VERSION",
version = Tags.VERSION,
name = StructureLibAPI.MOD_NAME,
acceptableRemoteVersions = "*",
guiFactory = "com.gtnewhorizon.structurelib.GuiFactory")
public class StructureLib {
Expand Down Expand Up @@ -95,6 +97,9 @@ public Item getTabIconItem() {
}
};

public static boolean isGTLoaded;
public static boolean isNEELoaded;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
ConfigurationHandler.INSTANCE.init(e.getSuggestedConfigurationFile());
Expand All @@ -112,6 +117,20 @@ public void preInit(FMLPreInitializationEvent e) {
if (Loader.isModLoaded(STRUCTURECOMPAT_MODID)) {
COMPAT = Loader.instance().getIndexedModList().get(STRUCTURECOMPAT_MODID).getMod();
}

isGTLoaded = Loader.isModLoaded("gregtech");
isNEELoaded = Loader.isModLoaded("neenergistics");
}

@Mod.EventHandler
// load "Do your mod setup. Build whatever data structures you care about. Register recipes."
public void init(FMLInitializationEvent event) {
proxy.init(event);
}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit(event);
}

@Mod.EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
public class StructureLibAPI {

public static final String MOD_ID = "structurelib";
public static final String MOD_NAME = "StructureLib";

public static final int HINT_BLOCK_META_GENERIC_0 = 0;
public static final int HINT_BLOCK_META_GENERIC_1 = 1;
public static final int HINT_BLOCK_META_GENERIC_2 = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.gtnewhorizon.structurelib.client.gui;

import net.minecraft.util.StatCollector;

import com.gtnewhorizon.structurelib.StructureLib;

public enum GuiText {

// UI Text
Tier,
Layer,
// UI Colors
FontColor(0x333333),
BgColor(0xC6C6C6),
ButtonEnabledColor(0x202020),
ButtonDisabledColor(0xA0A0A0),
ButtonHoveredColor(0xFFFFA0);

private final String root;
private final int color;

GuiText() {
this.root = "gui.blockrenderer6343";
this.color = 0x000000;
}

GuiText(final int hex) {
this.root = "gui.blockrenderer6343";
this.color = hex;
}

public int getColor() {
String hex = StatCollector.translateToLocal(this.getUnlocalized());
int color = this.color;
if (hex.length() <= 6) {
try {
color = Integer.parseUnsignedInt(hex, 16);
} catch (final NumberFormatException e) {
StructureLib.LOGGER.warn("Couldn't format color correctly for: " + this.root + " -> " + hex);
}
}
return color;
}

public String getLocal() {
return StatCollector.translateToLocal(this.getUnlocalized());
}

public String getUnlocalized() {
return this.root + '.' + this.toString();
}
}
Loading