generated from tilera/1710mod
feat: add researchtable extension API
This commit is contained in:
parent
89b713de99
commit
881e51ec6c
|
@ -24,7 +24,7 @@ apply from: './gradle/scripts/mixins.gradle'
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
version = "1.5.0"
|
version = "1.6.0"
|
||||||
group= "dev.tilera"
|
group= "dev.tilera"
|
||||||
archivesBaseName = "auracore"
|
archivesBaseName = "auracore"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package dev.tilera.auracore.api.research;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DO NOT IMPLEMENT THIS!
|
||||||
|
* Implemented by TileResearchTable. Can safely be casted to it.
|
||||||
|
*/
|
||||||
|
public interface IResearchTable {
|
||||||
|
|
||||||
|
ResearchTableExtension getInternalExtension();
|
||||||
|
|
||||||
|
World getWorld();
|
||||||
|
|
||||||
|
int getXCoord();
|
||||||
|
|
||||||
|
int getYCoord();
|
||||||
|
|
||||||
|
int getZCoord();
|
||||||
|
|
||||||
|
void openGUI(EntityPlayer player);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package dev.tilera.auracore.api.research;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public abstract class ResearchTableExtension {
|
||||||
|
|
||||||
|
public World world;
|
||||||
|
public int xCoord;
|
||||||
|
public int yCoord;
|
||||||
|
public int zCoord;
|
||||||
|
|
||||||
|
public ResearchTableExtension(IResearchTable researchTable) {
|
||||||
|
this.world = researchTable.getWorld();
|
||||||
|
this.xCoord = researchTable.getXCoord();
|
||||||
|
this.yCoord = researchTable.getYCoord();
|
||||||
|
this.zCoord = researchTable.getZCoord();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IResearchTable getResearchTable() {
|
||||||
|
TileEntity te = this.world.getTileEntity(this.xCoord, this.yCoord, this.zCoord);
|
||||||
|
if (te instanceof IResearchTable) {
|
||||||
|
return (IResearchTable) te;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void writeToNBT(NBTTagCompound nbt);
|
||||||
|
|
||||||
|
public abstract void readFromNBT(NBTTagCompound nbt);
|
||||||
|
|
||||||
|
public abstract void writeToPacket(NBTTagCompound nbt);
|
||||||
|
|
||||||
|
public abstract void readFromPacket(NBTTagCompound nbt);
|
||||||
|
|
||||||
|
public abstract void onTick();
|
||||||
|
|
||||||
|
public abstract void markDirty();
|
||||||
|
|
||||||
|
public abstract boolean openGUI(EntityPlayer player);
|
||||||
|
|
||||||
|
public abstract String getNBTKey();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package dev.tilera.auracore.api.research;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
|
public class ResearchTableExtensionRegistry {
|
||||||
|
|
||||||
|
private static Class<? extends ResearchTableExtension> extension = null;
|
||||||
|
|
||||||
|
public static boolean registerResearchTableExtension(Class<? extends ResearchTableExtension> ext, boolean force) {
|
||||||
|
if (extension == null || force) {
|
||||||
|
extension = ext;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasActiveExtension() {
|
||||||
|
return extension != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResearchTableExtension createInstance(IResearchTable table) {
|
||||||
|
try {
|
||||||
|
Constructor<?> constr = extension.getConstructor(IResearchTable.class);
|
||||||
|
return (ResearchTableExtension) constr.newInstance(table);
|
||||||
|
} catch (NullPointerException | ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Overwrite;
|
import org.spongepowered.asm.mixin.Overwrite;
|
||||||
|
|
||||||
import dev.tilera.auracore.AuraCore;
|
import dev.tilera.auracore.AuraCore;
|
||||||
|
import dev.tilera.auracore.api.research.IResearchTable;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -48,12 +49,12 @@ public abstract class MixinBlockTable extends BlockContainer {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (tileEntity instanceof TileResearchTable) {
|
if (tileEntity instanceof TileResearchTable) {
|
||||||
player.openGui(Thaumcraft.instance, 10, world, x, y, z);
|
((IResearchTable)tileEntity).openGUI(player);
|
||||||
} else {
|
} else {
|
||||||
for(int a = 2; a < 6; ++a) {
|
for(int a = 2; a < 6; ++a) {
|
||||||
TileEntity tile = world.getTileEntity(x + ForgeDirection.getOrientation(a).offsetX, y + ForgeDirection.getOrientation(a).offsetY, z + ForgeDirection.getOrientation(a).offsetZ);
|
TileEntity tile = world.getTileEntity(x + ForgeDirection.getOrientation(a).offsetX, y + ForgeDirection.getOrientation(a).offsetY, z + ForgeDirection.getOrientation(a).offsetZ);
|
||||||
if (tile != null && tile instanceof TileResearchTable) {
|
if (tile instanceof TileResearchTable) {
|
||||||
player.openGui(Thaumcraft.instance, 10, world, x + ForgeDirection.getOrientation(a).offsetX, y + ForgeDirection.getOrientation(a).offsetY, z + ForgeDirection.getOrientation(a).offsetZ);
|
((IResearchTable)tile).openGUI(player);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
package dev.tilera.auracore.mixins;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Overwrite;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
import dev.tilera.auracore.api.research.IResearchTable;
|
||||||
|
import dev.tilera.auracore.api.research.ResearchTableExtension;
|
||||||
|
import dev.tilera.auracore.api.research.ResearchTableExtensionRegistry;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.NetworkManager;
|
||||||
|
import net.minecraft.network.Packet;
|
||||||
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import thaumcraft.api.TileThaumcraft;
|
||||||
|
import thaumcraft.common.Thaumcraft;
|
||||||
|
import thaumcraft.common.tiles.TileResearchTable;
|
||||||
|
|
||||||
|
@Mixin(TileResearchTable.class)
|
||||||
|
public abstract class MixinTileResearchTable extends TileThaumcraft implements IResearchTable {
|
||||||
|
|
||||||
|
private ResearchTableExtension extension = null;
|
||||||
|
|
||||||
|
@Inject(method = "<init>()V", at = @At("TAIL"), remap = false)
|
||||||
|
public void constructorHead(CallbackInfo ci) {
|
||||||
|
if (ResearchTableExtensionRegistry.hasActiveExtension()) {
|
||||||
|
extension = ResearchTableExtensionRegistry.createInstance(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResearchTableExtension getInternalExtension() {
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World getWorld() {
|
||||||
|
return this.worldObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getXCoord() {
|
||||||
|
return this.xCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getYCoord() {
|
||||||
|
return this.yCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getZCoord() {
|
||||||
|
return this.zCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openGUI(EntityPlayer player) {
|
||||||
|
if (extension != null) {
|
||||||
|
if (extension.openGUI(player)) return;
|
||||||
|
}
|
||||||
|
player.openGui(Thaumcraft.instance, 10, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "markDirty", at = @At("TAIL"))
|
||||||
|
public void onMarkDirty(CallbackInfo ci) {
|
||||||
|
if (extension != null) {
|
||||||
|
extension.markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "updateEntity", at = @At("TAIL"))
|
||||||
|
public void onUpdateEntity(CallbackInfo ci) {
|
||||||
|
if (extension != null) {
|
||||||
|
extension.onTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
super.readFromNBT(nbttagcompound);
|
||||||
|
if (extension != null) {
|
||||||
|
String key = extension.getNBTKey();
|
||||||
|
if (!nbttagcompound.hasKey(key)) return;
|
||||||
|
NBTTagCompound nbt = nbttagcompound.getCompoundTag(key);
|
||||||
|
extension.readFromNBT(nbt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
super.writeToNBT(nbttagcompound);
|
||||||
|
if (extension != null) {
|
||||||
|
String key = extension.getNBTKey();
|
||||||
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
extension.writeToNBT(nbt);
|
||||||
|
nbttagcompound.setTag(key, nbt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Packet getDescriptionPacket() {
|
||||||
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||||
|
this.writeCustomNBT(nbttagcompound);
|
||||||
|
if (extension != null) {
|
||||||
|
String key = extension.getNBTKey();
|
||||||
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
extension.writeToPacket(nbt);
|
||||||
|
nbttagcompound.setTag(key, nbt);
|
||||||
|
}
|
||||||
|
return new S35PacketUpdateTileEntity(super.xCoord, super.yCoord, super.zCoord, -999, nbttagcompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tilera
|
||||||
|
* @reason ResearchTable extensions
|
||||||
|
*/
|
||||||
|
@Overwrite(remap = false)
|
||||||
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||||
|
super.onDataPacket(net, pkt);
|
||||||
|
if (super.worldObj != null && super.worldObj.isRemote) {
|
||||||
|
super.worldObj.markBlockForUpdate(super.xCoord, super.yCoord, super.zCoord);
|
||||||
|
}
|
||||||
|
if (extension != null) {
|
||||||
|
NBTTagCompound nbttagcompound = pkt.func_148857_g();
|
||||||
|
String key = extension.getNBTKey();
|
||||||
|
if (!nbttagcompound.hasKey(key)) return;
|
||||||
|
NBTTagCompound nbt = nbttagcompound.getCompoundTag(key);
|
||||||
|
extension.readFromNBT(nbt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,6 +12,7 @@
|
||||||
"MixinTileArcaneFurnace",
|
"MixinTileArcaneFurnace",
|
||||||
"MixinTileJarFillable",
|
"MixinTileJarFillable",
|
||||||
"MixinTileAlembic",
|
"MixinTileAlembic",
|
||||||
|
"MixinTileResearchTable",
|
||||||
"MixinBlockCustomPlant",
|
"MixinBlockCustomPlant",
|
||||||
"MixinBlockCustomOre",
|
"MixinBlockCustomOre",
|
||||||
"MixinBlockTable",
|
"MixinBlockTable",
|
||||||
|
|
Loading…
Reference in a new issue