Skip to content
This repository was archived by the owner on Apr 20, 2025. It is now read-only.
Merged
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
18 changes: 0 additions & 18 deletions addon.gradle

This file was deleted.

14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ developmentEnvironmentUserName = Developer

# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true

# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
Expand All @@ -50,27 +50,27 @@ enableGenericInjection = false
# 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.muxiu1997.mxrandom.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 = GRADLETOKEN_MODID
gradleTokenModId =

# [DEPRECATED] Mod name replacement token.
gradleTokenModName = GRADLETOKEN_MODNAME
gradleTokenModName =

# [DEPRECATED] Mod Group replacement token.
gradleTokenGroupName = GRADLETOKEN_GROUPNAME
gradleTokenGroupName =

# [DEPRECATED]
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
# public static final String VERSION = "GRADLETOKEN_VERSION";
# 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 = Tags.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 Down
40 changes: 40 additions & 0 deletions src/main/java/com/muxiu1997/mxrandom/MXRandom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.muxiu1997.mxrandom;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.muxiu1997.mxrandom.loader.GTMetaTileEntityLoader;
import com.muxiu1997.mxrandom.loader.NetworkLoader;
import com.muxiu1997.mxrandom.loader.RecipeLoader;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;

@Mod(
modid = MXRandom.MODID,
name = MXRandom.MODNAME,
version = Tags.VERSION,
dependencies = "required-after:appliedenergistics2;" + "required-after:gregtech")
public class MXRandom {

public static final String MODID = "mxrandom";
public static final String MODNAME = "MX-Random";

public static Logger logger = LogManager.getLogger(MODID);
public static final SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);

@EventHandler
public void onInit(FMLInitializationEvent event) {
GTMetaTileEntityLoader.load();
NetworkLoader.load();
}

@EventHandler
public void onPostInit(FMLPostInitializationEvent event) {
RecipeLoader.load();
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/muxiu1997/mxrandom/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.muxiu1997.mxrandom;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;

public class Utils {

public static IMetaTileEntity getMetaTileEntity(World w, int x, int y, int z) {
TileEntity te = w.getTileEntity(x, y, z);
if (te instanceof IGregTechTileEntity igtte) {
return igtte.getMetaTileEntity();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.muxiu1997.mxrandom.api;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.util.ForgeDirection;

import com.muxiu1997.mxrandom.MXRandom;
import com.muxiu1997.mxrandom.network.message.MessageSyncMetaTileEntityConfig;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import io.netty.buffer.ByteBuf;

public interface IConfigurableMetaTileEntity {

IGregTechTileEntity getBaseMetaTileEntity();

void readConfigFromBytes(ByteBuf buf);

void writeConfigToBytes(ByteBuf buf);

default void applyConfigChanges() {
IGregTechTileEntity te = getBaseMetaTileEntity();
te.markDirty();
if (te.isServerSide()) {
MXRandom.network.sendToServer(new MessageSyncMetaTileEntityConfig(this, false));
} else if (te.isClientSide()) {
MXRandom.network.sendToAll(new MessageSyncMetaTileEntityConfig(this, false));
}
}

Object getServerGuiElement(int ID, EntityPlayer player);

@SideOnly(Side.CLIENT)
Object getClientGuiElement(int ID, EntityPlayer player);

void onScrewdriverRightClick(ForgeDirection side, EntityPlayer player, float x, float y, float z);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.muxiu1997.mxrandom.api.network;

import org.jetbrains.annotations.NotNull;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;

public interface IMessageBothSideHandler<REQ extends IMessage, REPLY extends IMessage>
extends IMessageServerSideHandler<REQ, REPLY>, IMessageClientSideHandler<REQ, REPLY> {

@Override
default REPLY onMessage(@NotNull REQ message, @NotNull MessageContext ctx) {
if (ctx.side == Side.SERVER) {
return handleServerSideMessage(message, ctx);
} else {
return handleClientSideMessage(message, ctx);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.muxiu1997.mxrandom.api.network;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public interface IMessageClientSideHandler<REQ extends IMessage, REPLY extends IMessage>
extends IMessageHandler<REQ, REPLY> {

@Override
default REPLY onMessage(REQ message, MessageContext ctx) {
if (ctx.side == Side.SERVER) {
throw new IllegalAccessError("Cannot handle server-side messages");
}
return handleClientSideMessage(message, ctx);
}

@SideOnly(Side.CLIENT)
REPLY handleClientSideMessage(REQ message, MessageContext ctx);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.muxiu1997.mxrandom.api.network;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;

public interface IMessageServerSideHandler<REQ extends IMessage, REPLY extends IMessage>
extends IMessageHandler<REQ, REPLY> {

@Override
default REPLY onMessage(REQ message, MessageContext ctx) {
if (ctx.side == Side.CLIENT) {
throw new IllegalAccessError("Cannot handle client-side messages");
}
return handleServerSideMessage(message, ctx);
}

REPLY handleServerSideMessage(REQ message, MessageContext ctx);
}
71 changes: 71 additions & 0 deletions src/main/java/com/muxiu1997/mxrandom/client/fx/CraftingFX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.muxiu1997.mxrandom.client.fx;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

import appeng.api.storage.data.IAEItemStack;

public class CraftingFX extends EntityFX {

private final EntityItem entityItem;
private final boolean isItemBlock;

public CraftingFX(World w, double x, double y, double z, int age, IAEItemStack itemStack) {
super(w, x, y, z, 0, 0, 0);
this.entityItem = new EntityItem(this.worldObj, 0, 0, 0, itemStack.getItemStack());
this.entityItem.hoverStart = 0;
this.isItemBlock = itemStack.getItemStack().getItem() instanceof ItemBlock;

this.motionX = 0;
this.motionY = 0;
this.motionZ = 0;
this.particleMaxAge = age + 1;
this.noClip = true;
}

@Override
public void renderParticle(Tessellator tessellator, float renderPartialTicks, float rX, float rY, float rZ,
float rYZ, float rXY) {
Tessellator.instance.draw();
GL11.glPushMatrix();

float ticks = Minecraft.getMinecraft().renderViewEntity.ticksExisted;
double x = (prevPosX + (posX - prevPosX) * renderPartialTicks - interpPosX);
double y = (prevPosY + (posY - prevPosY) * renderPartialTicks - interpPosY);
double z = (prevPosZ + (posZ - prevPosZ) * renderPartialTicks - interpPosZ);
float h = MathHelper.sin(ticks % 32767.0f / 16.0f) * 0.05f;
float scale = isItemBlock ? 3.6f : 1.8f;

GL11.glTranslatef((float) x + 0.5f, (float) y + 0.15f + h, (float) z + 0.5f);
GL11.glRotatef(ticks % 360.0f, 0, 1, 0);
GL11.glScalef(scale, scale, scale);

RenderManager.instance.renderEntityWithPosYaw(entityItem, 0, 0, 0, 0, 0);

GL11.glPopMatrix();
Tessellator.instance.startDrawingQuads();
}

@Override
public int getBrightnessForRender(float partialTickTime) {
return super.getBrightnessForRender((15 << 20) | (15 << 4));
}

@Override
public int getFXLayer() {
return isItemBlock ? 1 : 2;
}

@Override
public boolean shouldRenderInPass(int pass) {
return pass == 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.muxiu1997.mxrandom.client.gui;

import java.awt.Color;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

import com.muxiu1997.mxrandom.MXRandom;
import com.muxiu1997.mxrandom.metatileentity.MTELargeMolecularAssembler;
import com.muxiu1997.mxrandom.network.container.ContainerConfigLargeMolecularAssembler;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiConfigLargeMolecularAssembler extends GuiContainer {

private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(
MXRandom.MODID,
"textures/gui/configMetaTileEntity.png");
private static final String LANG_CRAFTING_FX = "mxrandom.client.gui.GuiConfigLargeMolecularAssembler.craftingFX";
private static final String LANG_VISIBLE = "mxrandom.client.gui.GuiConfigLargeMolecularAssembler.visible";
private static final String LANG_HIDDEN = "mxrandom.client.gui.GuiConfigLargeMolecularAssembler.hidden";

private static final int PADDING = 8;
private static final int BUTTON_WIDTH = 40;
private static final int BUTTON_HEIGHT = 18;

private GuiButton buttonToggleCraftingFX;
private final MTELargeMolecularAssembler LMA;

public GuiConfigLargeMolecularAssembler(ContainerConfigLargeMolecularAssembler container) {
super(container);
this.LMA = container.LMA;
this.xSize = 176;
this.ySize = 107;
}

@Override
public void initGui() {
super.initGui();
buttonToggleCraftingFX = new GuiButton(
0,
guiLeft + xSize - BUTTON_WIDTH - PADDING,
guiTop + PADDING + 16,
BUTTON_WIDTH,
BUTTON_HEIGHT,
buttonToggleCraftingFXDisplayString());
buttonList.add(buttonToggleCraftingFX);
}

@Override
public void updateScreen() {
super.updateScreen();
buttonToggleCraftingFX.displayString = buttonToggleCraftingFXDisplayString();
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
this.mc.getTextureManager().bindTexture(BACKGROUND_TEXTURE);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}

@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
fontRendererObj.drawString(LMA.getLocalName(), PADDING, PADDING, Color.BLACK.getRGB());
fontRendererObj.drawString(
StatCollector.translateToLocal(LANG_CRAFTING_FX),
PADDING,
PADDING + 20,
Color.BLACK.getRGB());
}

@Override
protected void actionPerformed(GuiButton button) {
if (button == buttonToggleCraftingFX) {
LMA.hiddenCraftingFX = !LMA.hiddenCraftingFX;
LMA.applyConfigChanges();
}
}

private String buttonToggleCraftingFXDisplayString() {
if (LMA.hiddenCraftingFX) {
return StatCollector.translateToLocal(LANG_HIDDEN);
}
return StatCollector.translateToLocal(LANG_VISIBLE);
}
}
Loading
Loading