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

Astral Rift Generator #606

Draft
wants to merge 4 commits into
base: main
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
3 changes: 3 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ dependencies {
//These 2 deps have conflicts with Amun-Ra by default, see Twist-Space-Technology-Mod#150
compileOnly('curse.maven:witchery-69673:2234410')
implementation('com.github.GTNewHorizons:WitcheryExtras:1.2.2:dev')
compileOnly('com.github.GTNewHorizons:BloodMagic:1.6.2:dev')
implementation 'com.google.auto.value:auto-value-annotations:1.10.1'
annotationProcessor 'com.google.auto.value:auto-value:1.10.1'
// implementation('com.github.RealSilverMoon:BoxPlusPlus:1.2.0:dev')
}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ apiPackage =
accessTransformersFile =

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

# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false
Expand All @@ -92,12 +92,12 @@ usesMixinDebug = false
mixinPlugin =

# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage =
mixinsPackage = mixin

# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
coreModClass =
coreModClass = TwistSpaceTechnology

# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package com.Nxer.TwistSpaceTechnology.ASM;

import net.minecraft.launchwrapper.IClassTransformer;

import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.ClassVisitor;
import org.spongepowered.asm.lib.ClassWriter;
import org.spongepowered.asm.lib.Label;
import org.spongepowered.asm.lib.MethodVisitor;
import org.spongepowered.asm.lib.Opcodes;

public class BaseMetaTileEntityASM implements IClassTransformer {

@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
// 捕获BaseMetaTileEntity类的加载
if ("gregtech.api.metatileentity.BaseMetaTileEntity".equals(transformedName)) {
return transformBaseClass(basicClass);
}
return basicClass;
}

private byte[] transformBaseClass(byte[] basicClass) {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
ClassVisitor classVisitor = new BaseClassVisitor(Opcodes.ASM5, classWriter);
classReader.accept(classVisitor, 0);
return classWriter.toByteArray();
}

static class BaseClassVisitor extends ClassVisitor {

public BaseClassVisitor(int api, ClassVisitor classVisitor) {
super(api, classVisitor);
}

@Override
public void visitEnd() {
// 访问getRenderBoundingBox方法
MethodVisitor mv = cv.visitMethod(
Opcodes.ACC_PUBLIC,
"getRenderBoundingBox",
"()Lnet/minecraft/util/AxisAlignedBB;",
null,
null);
if (mv != null) {
mv.visitCode();

// 将“this”加载到堆栈上
mv.visitVarInsn(Opcodes.ALOAD, 0);

// 调用getMetaTileEntity方法
mv.visitMethodInsn(
Opcodes.INVOKEVIRTUAL,
"gregtech/api/metatileentity/BaseMetaTileEntity",
"getMetaTileEntity",
"()Lgregtech/api/interfaces/metatileentity/IMetaTileEntity;",
false);

// 判断是否来自于IMachineTESR的实例
mv.visitTypeInsn(Opcodes.INSTANCEOF, "com/Nxer/TwistSpaceTechnology/client/render/IMachineTESR");

// 如果为false则跳过调用
Label ifFalse = new Label();
mv.visitJumpInsn(Opcodes.IFEQ, ifFalse);

// 将类型转换为IMachineTESR,并调用IMachineTESR接口的getRenderBoundingBox方法
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(
Opcodes.INVOKEVIRTUAL,
"gregtech/api/metatileentity/BaseMetaTileEntity",
"getMetaTileEntity",
"()Lgregtech/api/interfaces/metatileentity/IMetaTileEntity;",
false);
mv.visitTypeInsn(Opcodes.CHECKCAST, "com/Nxer/TwistSpaceTechnology/client/render/IMachineTESR");
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(
Opcodes.INVOKEINTERFACE,
"com/Nxer/TwistSpaceTechnology/client/render/IMachineTESR",
"getRenderBoundingBox",
"(Lgregtech/api/metatileentity/BaseMetaTileEntity;)Lnet/minecraft/util/AxisAlignedBB;",
true);
mv.visitInsn(Opcodes.ARETURN);

mv.visitLabel(ifFalse);

// 如果为false则调用原来父类的方法
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(
Opcodes.INVOKESPECIAL,
"gregtech/api/metatileentity/CommonMetaTileEntity",
"getRenderBoundingBox",
"()Lnet/minecraft/util/AxisAlignedBB;",
false);
mv.visitInsn(Opcodes.ARETURN);

mv.visitMaxs(3, 1);
mv.visitEnd();
}
MethodVisitor mv1 = cv.visitMethod(Opcodes.ACC_PUBLIC, "getMaxRenderDistanceSquared", "()D", null, null);
if (mv1 != null) {
mv1.visitCode();

// 将“this”加载到堆栈上
mv1.visitVarInsn(Opcodes.ALOAD, 0);

// 调用getMetaTileEntity方法
mv1.visitMethodInsn(
Opcodes.INVOKEVIRTUAL,
"gregtech/api/metatileentity/BaseMetaTileEntity",
"getMetaTileEntity",
"()Lgregtech/api/interfaces/metatileentity/IMetaTileEntity;",
false);

// 判断是否来自于IMachineTESR的实例
mv1.visitTypeInsn(Opcodes.INSTANCEOF, "com/Nxer/TwistSpaceTechnology/client/render/IMachineTESR");

// 如果为false则跳过调用
Label ifFalse = new Label();
mv1.visitJumpInsn(Opcodes.IFEQ, ifFalse);

// 将类型转换为IMachineTESR,并调用IMachineTESR接口的getMaxRenderDistanceSquared方法
mv1.visitVarInsn(Opcodes.ALOAD, 0);
mv1.visitMethodInsn(
Opcodes.INVOKEVIRTUAL,
"gregtech/api/metatileentity/BaseMetaTileEntity",
"getMetaTileEntity",
"()Lgregtech/api/interfaces/metatileentity/IMetaTileEntity;",
false);
mv1.visitTypeInsn(Opcodes.CHECKCAST, "com/Nxer/TwistSpaceTechnology/client/render/IMachineTESR");
mv1.visitMethodInsn(
Opcodes.INVOKEINTERFACE,
"com/Nxer/TwistSpaceTechnology/client/render/IMachineTESR",
"getMaxRenderDistanceSquared",
"()D",
true);
mv1.visitInsn(Opcodes.DRETURN);

mv1.visitLabel(ifFalse);

// 如果为false则调用原来父类的方法
mv1.visitVarInsn(Opcodes.ALOAD, 0);
mv1.visitMethodInsn(
Opcodes.INVOKESPECIAL,
"gregtech/api/metatileentity/CommonMetaTileEntity",
"getMaxRenderDistanceSquared",
"()D",
false);
mv1.visitInsn(Opcodes.DRETURN);

mv1.visitMaxs(3, 1);
mv1.visitEnd();
}
super.visitEnd();
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/com/Nxer/TwistSpaceTechnology/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.Nxer.TwistSpaceTechnology.client.Sound.SoundLoader;
import com.Nxer.TwistSpaceTechnology.client.render.ArtificialStarRender;
import com.Nxer.TwistSpaceTechnology.common.machine.TST_BigBroArray;
import com.Nxer.TwistSpaceTechnology.loader.RendereLoader;
import com.Nxer.TwistSpaceTechnology.loader.RendererLoader;
import com.Nxer.TwistSpaceTechnology.system.ItemCooldown.CooldownEventHandler;

import cpw.mods.fml.common.event.FMLInitializationEvent;
Expand All @@ -26,7 +26,9 @@ public void init(FMLInitializationEvent event) {
@Override
public void postInit(FMLPostInitializationEvent event) {
super.postInit(event);
new RendereLoader();
RendererLoader loader = new RendererLoader();
loader.registerTileEntityRenderers();
loader.registerItemRenderers();
new SoundLoader();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static com.Nxer.TwistSpaceTechnology.loader.RecipeLoader.loadRecipesServerStarted;

import java.util.Map;

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

Expand Down Expand Up @@ -30,14 +32,17 @@
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;

@Mod(
modid = Tags.MODID,
version = Tags.VERSION,
name = Tags.MODNAME,
dependencies = "required-before:gregtech; " + "before:dreamcraft;",
acceptedMinecraftVersions = "[1.7.10]")
public class TwistSpaceTechnology {
@IFMLLoadingPlugin.MCVersion("1.7.10")
@IFMLLoadingPlugin.TransformerExclusions({ "com.Nxer.TwistSpaceTechnology" })
public class TwistSpaceTechnology implements IFMLLoadingPlugin {

/**
* <li>The signal of whether in Development Mode.
Expand Down Expand Up @@ -148,4 +153,26 @@ public void serverStarted(FMLServerStartedEvent event) {
loadRecipesServerStarted();
}

@Override
public String[] getASMTransformerClass() {
return new String[] { "com.Nxer.TwistSpaceTechnology.ASM.BaseMetaTileEntityASM" };
}

@Override
public String getModContainerClass() {
return null;
}

@Override
public String getSetupClass() {
return null;
}

@Override
public void injectData(Map<String, Object> data) {}

@Override
public String getAccessTransformerClass() {
return null;
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/Nxer/TwistSpaceTechnology/client/ModelEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.Nxer.TwistSpaceTechnology.client;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;

public enum ModelEnum {

PowerChair,
Yamato,
STAR;

private IModelCustom Model;

ModelEnum() {}

public ModelEnum set(ResourceLocation resourceLocation) {
this.Model = AdvancedModelLoader.loadModel(resourceLocation);;
return this;
}

public IModelCustom get() {
return this.Model;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;

import org.lwjgl.opengl.GL11;

import com.Nxer.TwistSpaceTechnology.client.ModelEnum;
import com.Nxer.TwistSpaceTechnology.common.tile.TileStar;

import cpw.mods.fml.client.registry.ClientRegistry;
Expand All @@ -19,8 +18,6 @@
public class ArtificialStarRender extends TileEntitySpecialRenderer {

private static final ResourceLocation STARTEXTURE = new ResourceLocation("gtnhcommunitymod:model/Star.png");
private static final IModelCustom STAR = AdvancedModelLoader
.loadModel(new ResourceLocation("gtnhcommunitymod:model/Sol.obj"));

public ArtificialStarRender() {
ClientRegistry.bindTileEntitySpecialRenderer(TileStar.class, this);
Expand All @@ -45,7 +42,8 @@ private void renderStar(double size) {
this.bindTexture(STARTEXTURE);
GL11.glScaled(size, size, size);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
STAR.renderAll();
ModelEnum.STAR.get()
.renderAll();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_CULL_FACE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.Nxer.TwistSpaceTechnology.client.render;

import static net.minecraft.tileentity.TileEntity.INFINITE_EXTENT_AABB;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

import gregtech.api.metatileentity.BaseMetaTileEntity;

public interface IMachineTESR {

// 如果您不熟悉OpenGL操作,请不要实现此接口!!!
void render(TileEntitySpecialRenderer TESR, TileEntity TileEntity, double x, double y, double z,
float timeSinceLastTick);

/**
* Return an {@link AxisAlignedBB} that controls the visible scope of a {@link TileEntitySpecialRenderer} associated
* with this {@link TileEntity}
* Defaults to the collision bounding box {@link Block#getCollisionBoundingBoxFromPool(World, int, int, int)}
* associated with the block
* at this location.
*
* @return an appropriately size {@link AxisAlignedBB} for the {@link TileEntity}
*/

default AxisAlignedBB getRenderBoundingBox(BaseMetaTileEntity baseMetaTile) {
return INFINITE_EXTENT_AABB;
}

// 最大渲染距离
default double getMaxRenderDistanceSquared() {
return 4096.0D;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

import com.Nxer.TwistSpaceTechnology.common.block.blockClass.ItemBlockPowerChair;

public class PowerChairRenderer implements IItemRenderer {
public class ItemPowerChairRenderer implements IItemRenderer {

protected IModelCustom models;
protected ResourceLocation textures;

public PowerChairRenderer(final IModelCustom models, final ResourceLocation textures) {
public ItemPowerChairRenderer(final IModelCustom models, final ResourceLocation textures) {
this.models = models;
this.textures = textures;
}
Expand Down
Loading
Loading