mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-26 15:03:03 +00:00
Some work on SubTiles.
This commit is contained in:
1 parent
13d95c53d5
commit
7f7ff14146
4 files changed
+127
-11
No files matched your search
@@ -20,13 +20,24 @@ import net.minecraft.item.crafting.IRecipe;
|
||||
import vazkii.botania.api.internal.DummyMethodHandler;
|
||||
import vazkii.botania.api.internal.IInternalMethodHandler;
|
||||
import vazkii.botania.api.internal.RecipePetals;
|
||||
import vazkii.botania.api.internal.SubTileDummy;
|
||||
import vazkii.botania.api.subtile.SubTileEntity;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
public final class BotaniaAPI {
|
||||
|
||||
private static List<LexiconCategory> categories = new ArrayList<LexiconCategory>();
|
||||
private static List<LexiconEntry> allEntries = new ArrayList<LexiconEntry>();
|
||||
|
||||
public static List<RecipePetals> petalRecipes = new ArrayList<RecipePetals>();
|
||||
|
||||
|
||||
private static BiMap<String, Class<? extends SubTileEntity>> subTiles = HashBiMap.<String, Class<? extends SubTileEntity>> create();
|
||||
static {
|
||||
registerSubTile("", SubTileDummy.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The internal method handler in use. Do not overwrite.
|
||||
* @see IInternalMethodHandler
|
||||
@@ -46,6 +57,10 @@ public final class BotaniaAPI {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public static void registerSubTile(String key, Class<? extends SubTileEntity> subtileClass) {
|
||||
subTiles.put(key, subtileClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a category to the list of registered categories to appear in the Lexicon.
|
||||
*/
|
||||
@@ -87,4 +102,15 @@ public final class BotaniaAPI {
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
public static Class<? extends SubTileEntity> getSubTileMapping(String key) {
|
||||
if(!subTiles.containsKey(key))
|
||||
key = "";
|
||||
|
||||
return subTiles.get(key);
|
||||
}
|
||||
|
||||
public static String getSubTileStringMapping(Class<? extends SubTileEntity> clazz) {
|
||||
return subTiles.inverse().get(clazz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [Jan 24, 2014, 4:17:33 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.internal;
|
||||
|
||||
import vazkii.botania.api.subtile.SubTileEntity;
|
||||
|
||||
public class SubTileDummy extends SubTileEntity {
|
||||
|
||||
}
|
||||
@@ -11,7 +11,8 @@
|
||||
*/
|
||||
package vazkii.botania.api.subtile;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* A Sub-TileEntity, this is used for the flower system. Make sure to map subclasses
|
||||
@@ -20,10 +21,28 @@ import net.minecraft.world.World;
|
||||
*/
|
||||
public class SubTileEntity {
|
||||
|
||||
World worldObj;
|
||||
TileEntity supertile;
|
||||
|
||||
public void setWorld(World world) {
|
||||
worldObj = world;
|
||||
public void setSupertile(TileEntity tile) {
|
||||
supertile = tile;
|
||||
}
|
||||
|
||||
public boolean canUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onUpdate() { }
|
||||
|
||||
/**
|
||||
* Writes some extra data to a network packet. This data is read
|
||||
* by readFromPacketNBT on the client that receives the packet.
|
||||
*/
|
||||
public void writeToPacketNBT(NBTTagCompound cmp) { }
|
||||
|
||||
/**
|
||||
* Reads data from a network packet. This data is written by
|
||||
* writeToPacketNBT in the server.
|
||||
*/
|
||||
public void readFromPacketNBT(NBTTagCompound cmp) { }
|
||||
|
||||
}
|
||||
@@ -11,18 +11,71 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import vazkii.botania.api.subtile.SubTileEntity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.subtile.SubTileEntity;
|
||||
|
||||
public abstract class TileSpecialFlower extends TileEntity {
|
||||
public abstract class TileSpecialFlower<T extends SubTileEntity> extends TileMod {
|
||||
|
||||
private static final String TAG_SUBTILE_NAME = "subTileName";
|
||||
private static final String TAG_SUBTILE_CMP = "subTileCmp";
|
||||
|
||||
String subTileName = "";
|
||||
SubTileEntity subTile;
|
||||
T subTile;
|
||||
|
||||
private void provideSubTile() {
|
||||
|
||||
public void setSubTile(String name) {
|
||||
subTileName = name;
|
||||
provideSubTile(subTileName);
|
||||
}
|
||||
|
||||
|
||||
public void setSubTile(T tile) {
|
||||
subTile = tile;
|
||||
}
|
||||
|
||||
private void provideSubTile(String name) {
|
||||
subTileName = name;
|
||||
|
||||
Class<? extends SubTileEntity> tileClass = BotaniaAPI.getSubTileMapping(name);
|
||||
try {
|
||||
T tile = (T) tileClass.newInstance();
|
||||
setSubTile(tile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
subTile.onUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate() {
|
||||
return subTile.canUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCustomNBT(NBTTagCompound cmp) {
|
||||
super.writeCustomNBT(cmp);
|
||||
|
||||
cmp.setString(TAG_SUBTILE_NAME, subTileName);
|
||||
NBTTagCompound subCmp = new NBTTagCompound();
|
||||
cmp.setCompoundTag(TAG_SUBTILE_CMP, subCmp);
|
||||
subTile.writeToPacketNBT(cmp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound cmp) {
|
||||
super.readCustomNBT(cmp);
|
||||
|
||||
subTileName = cmp.getString(subTileName);
|
||||
NBTTagCompound subCmp = cmp.getCompoundTag(TAG_SUBTILE_CMP);
|
||||
|
||||
if(subTile == null || !BotaniaAPI.getSubTileStringMapping(subTile.getClass()).equals(subTileName))
|
||||
provideSubTile(subTileName);
|
||||
|
||||
subTile.readFromNBT(subCmp);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user