mirror of
https://github.com/GTNewHorizons/Hardcore-Ender-Expansion.git
synced 2026-10-26 14:24:03 +00:00
Ender Compendium syncing, KO & KF progress
This commit is contained in:
1 parent
d493de36ca
commit
ce472f34b4
18 files changed
+405
-57
No files matched your search
@@ -15,7 +15,8 @@ import chylex.hee.gui.helpers.GuiEndPortalRenderer;
|
||||
import chylex.hee.gui.helpers.GuiItemRenderHelper;
|
||||
import chylex.hee.gui.helpers.GuiItemRenderHelper.ITooltipRenderer;
|
||||
import chylex.hee.mechanics.compendium.content.KnowledgeCategories;
|
||||
import chylex.hee.mechanics.compendium.content.fragments.KnowledgeCategory;
|
||||
import chylex.hee.mechanics.compendium.content.type.KnowledgeCategory;
|
||||
import chylex.hee.mechanics.compendium.player.PlayerCompendiumData;
|
||||
import chylex.hee.mechanics.knowledge.util.IGuiItemStackRenderer;
|
||||
import chylex.hee.system.util.MathUtil;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -34,6 +35,8 @@ public class GuiEnderCompendium extends GuiScreen implements ITooltipRenderer{
|
||||
return prevValue+(value-prevValue)*partialTickTime;
|
||||
}
|
||||
|
||||
private final PlayerCompendiumData compendiumData;
|
||||
|
||||
private GuiEndPortalRenderer portalRenderer;
|
||||
private List<AnimatedFloat> animationList = new ArrayList<>();
|
||||
private AnimatedFloat offsetX, offsetY, portalScale;
|
||||
@@ -42,7 +45,8 @@ public class GuiEnderCompendium extends GuiScreen implements ITooltipRenderer{
|
||||
|
||||
private List<CategoryDisplayElement> categoryElements = new ArrayList<CategoryDisplayElement>();
|
||||
|
||||
public GuiEnderCompendium(){
|
||||
public GuiEnderCompendium(PlayerCompendiumData compendiumData){
|
||||
this.compendiumData = compendiumData;
|
||||
animationList.add(offsetX = new AnimatedFloat(Easing.CUBIC));
|
||||
animationList.add(offsetY = new AnimatedFloat(Easing.CUBIC));
|
||||
animationList.add(portalScale = new AnimatedFloat(Easing.LINEAR));
|
||||
@@ -128,6 +132,9 @@ public class GuiEnderCompendium extends GuiScreen implements ITooltipRenderer{
|
||||
drawTexturedModalRect(d-16,height-d-8,0,25,24,24);
|
||||
drawTexturedModalRect(width-d-8,height-d-8,25,25,24,24);
|
||||
|
||||
String title = "Hardcore Ender Expansion - Ender Compendium";
|
||||
fontRendererObj.drawString(title,(width>>1)-(fontRendererObj.getStringWidth(title)>>1),6,4210752);
|
||||
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
for(CategoryDisplayElement element:categoryElements)element.render(this,(int)offsetX.value(),(int)offsetY.value(),partialTickTime);
|
||||
|
||||
@@ -54,8 +54,15 @@ public class ItemSpawnEggs extends ItemMonsterPlacer{
|
||||
return damage >= 0 && damage < eggTypes.length ? eggTypes[damage] : null;
|
||||
}
|
||||
|
||||
public static int getDamageForMob(Class<?> mobClass){
|
||||
for(int damage = 0; damage < eggTypes.length; damage++){
|
||||
if (eggTypes[damage].entityClass == mobClass)return damage;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ItemSpawnEggs(){
|
||||
super();
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,19 @@ package chylex.hee.mechanics.compendium.content;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import chylex.hee.block.BlockList;
|
||||
import chylex.hee.mechanics.compendium.content.fragments.KnowledgeCategory;
|
||||
import chylex.hee.mechanics.compendium.content.type.KnowledgeCategory;
|
||||
|
||||
public class KnowledgeCategories{
|
||||
private static final byte iconSize = KnowledgeCategory.iconSize;
|
||||
|
||||
public static KnowledgeCategory OVERWORLD, DRAGON_LAIR, ENDSTONE_BLOBS, DUNGEON_TOWER, METEOROIDS, BIOME_ISLAND_FOREST, BIOME_ISLAND_MOUNTAINS, BIOME_ISLAND_ENCHISLAND;
|
||||
|
||||
public static final KnowledgeCategory[] categoryList = new KnowledgeCategory[]{
|
||||
OVERWORLD = new KnowledgeCategory(0, -iconSize*2, 0, "Overworld", new ItemStack(Blocks.stonebrick)),
|
||||
DRAGON_LAIR = new KnowledgeCategory(1, -iconSize, 0, "Dragon Lair", new ItemStack(Blocks.dragon_egg)),
|
||||
OVERWORLD = new KnowledgeCategory(0, -2, 0, "Overworld", new ItemStack(Blocks.stonebrick)),
|
||||
DRAGON_LAIR = new KnowledgeCategory(1, -1, 0, "Dragon Lair", new ItemStack(Blocks.dragon_egg)),
|
||||
ENDSTONE_BLOBS = new KnowledgeCategory(2, 0, 0, "Endstone Blobs", new ItemStack(Blocks.end_stone)),
|
||||
DUNGEON_TOWER = new KnowledgeCategory(3, iconSize, 0, "Dungeon Tower", new ItemStack(BlockList.obsidian_special, 1, 1)),
|
||||
METEOROIDS = new KnowledgeCategory(4, iconSize*2, 0, "Meteoroids", new ItemStack(BlockList.sphalerite)),
|
||||
BIOME_ISLAND_FOREST = new KnowledgeCategory(5, iconSize*3, -iconSize, "Biome Island - Infested Forest", new ItemStack(BlockList.end_terrain, 1, 0)),
|
||||
BIOME_ISLAND_MOUNTAINS = new KnowledgeCategory(6, iconSize*3, 0, "Biome Island - Burning Mountains", new ItemStack(BlockList.end_terrain, 1, 1)),
|
||||
BIOME_ISLAND_ENCHISLAND = new KnowledgeCategory(7, iconSize*3, iconSize, "Biome Island - Enchanted Island", new ItemStack(BlockList.end_terrain, 1, 2))
|
||||
DUNGEON_TOWER = new KnowledgeCategory(3, 1, 0, "Dungeon Tower", new ItemStack(BlockList.obsidian_special, 1, 1)),
|
||||
METEOROIDS = new KnowledgeCategory(4, 2, 0, "Meteoroids", new ItemStack(BlockList.sphalerite)),
|
||||
BIOME_ISLAND_FOREST = new KnowledgeCategory(5, 3, -1, "Biome Island - Infested Forest", new ItemStack(BlockList.end_terrain, 1, 0)),
|
||||
BIOME_ISLAND_MOUNTAINS = new KnowledgeCategory(6, 3, 0, "Biome Island - Burning Mountains", new ItemStack(BlockList.end_terrain, 1, 1)),
|
||||
BIOME_ISLAND_ENCHISLAND = new KnowledgeCategory(7, 3, 1, "Biome Island - Enchanted Island", new ItemStack(BlockList.end_terrain, 1, 2))
|
||||
};
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package chylex.hee.mechanics.compendium.content;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
import chylex.hee.mechanics.compendium.content.fragments.KnowledgeFragment;
|
||||
|
||||
public final class KnowledgeFragments{
|
||||
private static final TIntObjectMap<KnowledgeFragment> fragmentMap = new TIntObjectHashMap<>();
|
||||
|
||||
public static KnowledgeFragment getById(int id){
|
||||
return fragmentMap.get(id);
|
||||
}
|
||||
|
||||
public static void initialize(){
|
||||
//
|
||||
|
||||
for(KnowledgeFragment fragment:KnowledgeFragment.getAllFragments())fragmentMap.put(fragment.globalID,fragment);
|
||||
}
|
||||
|
||||
private KnowledgeFragments(){}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package chylex.hee.mechanics.compendium.content;
|
||||
import net.minecraft.init.Blocks;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
import chylex.hee.mechanics.compendium.content.objects.ObjectBlock;
|
||||
import chylex.hee.mechanics.compendium.content.type.KnowledgeFragment;
|
||||
import chylex.hee.mechanics.compendium.content.type.KnowledgeFragmentText;
|
||||
import chylex.hee.mechanics.compendium.content.type.KnowledgeObject;
|
||||
|
||||
public final class KnowledgeRegistrations{
|
||||
private static final TIntObjectMap<KnowledgeFragment> fragmentMap = new TIntObjectHashMap<>();
|
||||
|
||||
public static KnowledgeFragment getById(int id){
|
||||
return fragmentMap.get(id);
|
||||
}
|
||||
|
||||
public static KnowledgeObject getObject(Object obj){ // TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final KnowledgeObject<ObjectBlock> TEST_OBJECT = new KnowledgeObject<>(new ObjectBlock(Blocks.bedrock));
|
||||
|
||||
public static void initialize(){
|
||||
KnowledgeCategories.OVERWORLD.addKnowledgeObjects(new KnowledgeObject[]{
|
||||
TEST_OBJECT.setPos(0,0).setFragments(new KnowledgeFragment[]{
|
||||
new KnowledgeFragmentText(1000).setContents("Test fragment").setPrice(5)
|
||||
})
|
||||
});
|
||||
|
||||
for(KnowledgeFragment fragment:KnowledgeFragment.getAllFragments())fragmentMap.put(fragment.globalID,fragment);
|
||||
}
|
||||
|
||||
private KnowledgeRegistrations(){}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package chylex.hee.mechanics.compendium.content.fragments;
|
||||
|
||||
public class KnowledgeObject<T>{
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package chylex.hee.mechanics.compendium.content.objects;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IKnowledgeObjectInstance<T>{
|
||||
public ItemStack createItemStackToRender();
|
||||
public boolean areObjectsEqual(T obj1, T obj2);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package chylex.hee.mechanics.compendium.content.objects;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import chylex.hee.mechanics.compendium.content.objects.ObjectBlock.BlockMetaWrapper;
|
||||
|
||||
public class ObjectBlock implements IKnowledgeObjectInstance<BlockMetaWrapper>{
|
||||
private final BlockMetaWrapper wrapper;
|
||||
|
||||
public ObjectBlock(Block block){
|
||||
this.wrapper = new BlockMetaWrapper(block,-1);
|
||||
}
|
||||
|
||||
public ObjectBlock(Block block, int metadata){
|
||||
this.wrapper = new BlockMetaWrapper(block,metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStackToRender(){
|
||||
return new ItemStack(wrapper.block,1,wrapper.metadata == OreDictionary.WILDCARD_VALUE ? 0 : wrapper.metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areObjectsEqual(BlockMetaWrapper obj1, BlockMetaWrapper obj2){
|
||||
return obj1.block == obj2.block && (obj1.metadata == obj2.metadata || obj1.metadata == -1 || obj2.metadata == -1);
|
||||
}
|
||||
|
||||
public static class BlockMetaWrapper{
|
||||
public final Block block;
|
||||
public final byte metadata;
|
||||
|
||||
public BlockMetaWrapper(Block block, int metadata){
|
||||
this.block = block;
|
||||
this.metadata = (byte)metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package chylex.hee.mechanics.compendium.content.objects;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ObjectItem implements IKnowledgeObjectInstance<Item>{
|
||||
private final Item item;
|
||||
|
||||
public ObjectItem(Item item){
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStackToRender(){
|
||||
return new ItemStack(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areObjectsEqual(Item obj1, Item obj2){
|
||||
return obj1 == obj2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package chylex.hee.mechanics.compendium.content.objects;
|
||||
import chylex.hee.item.ItemList;
|
||||
import chylex.hee.item.ItemSpawnEggs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ObjectMob implements IKnowledgeObjectInstance<Class<? extends EntityLivingBase>>{
|
||||
private final Class<? extends EntityLivingBase> mobClass;
|
||||
|
||||
public ObjectMob(Class<? extends EntityLivingBase> mobClass){
|
||||
this.mobClass = mobClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStackToRender(){
|
||||
int spawnEggDamage = ItemSpawnEggs.getDamageForMob(mobClass);
|
||||
return spawnEggDamage == -1 ? new ItemStack(Blocks.bedrock) : new ItemStack(ItemList.spawn_eggs,1,spawnEggDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areObjectsEqual(Class<? extends EntityLivingBase> obj1, Class<? extends EntityLivingBase> obj2){
|
||||
return obj1 == obj2;
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -1,4 +1,6 @@
|
||||
package chylex.hee.mechanics.compendium.content.fragments;
|
||||
package chylex.hee.mechanics.compendium.content.type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import chylex.hee.mechanics.knowledge.util.IGuiItemStackRenderer;
|
||||
|
||||
@@ -9,14 +11,19 @@ public class KnowledgeCategory implements IGuiItemStackRenderer{
|
||||
private final int x, y;
|
||||
private final String tooltip;
|
||||
private final ItemStack showcaseItem;
|
||||
private final List<KnowledgeObject> objectList = new ArrayList<>();
|
||||
|
||||
public KnowledgeCategory(int id, int x, int y, String tooltip, ItemStack showcaseItem){
|
||||
this.id = (byte)id;
|
||||
this.x = x-iconSize;
|
||||
this.y = y-(iconSize>>1);
|
||||
this.x = x*iconSize-iconSize;
|
||||
this.y = y*iconSize-(iconSize>>1);
|
||||
this.tooltip = tooltip;
|
||||
this.showcaseItem = showcaseItem;
|
||||
}
|
||||
|
||||
public void addKnowledgeObjects(KnowledgeObject[] objects){
|
||||
for(KnowledgeObject object:objects)objectList.add(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX(){
|
||||
+20
-1
@@ -1,8 +1,11 @@
|
||||
package chylex.hee.mechanics.compendium.content.fragments;
|
||||
package chylex.hee.mechanics.compendium.content.type;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class KnowledgeFragment{
|
||||
private static final Set<KnowledgeFragment> allFragments = new HashSet<>();
|
||||
@@ -13,6 +16,7 @@ public abstract class KnowledgeFragment{
|
||||
|
||||
public final int globalID;
|
||||
private int price = 10;
|
||||
private boolean unlockOnDiscovery = false;
|
||||
private int[] unlockRequirements = ArrayUtils.EMPTY_INT_ARRAY;
|
||||
|
||||
public KnowledgeFragment(int globalID){
|
||||
@@ -38,10 +42,25 @@ public abstract class KnowledgeFragment{
|
||||
return price != -1;
|
||||
}
|
||||
|
||||
public KnowledgeFragment setUnlockOnDiscovery(){
|
||||
this.unlockOnDiscovery = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isUnlockedOnDiscovery(){
|
||||
return unlockOnDiscovery;
|
||||
}
|
||||
|
||||
public KnowledgeFragment setUnlockRequirements(int...requirements){
|
||||
this.unlockRequirements = requirements;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract int getHeight(Minecraft mc, boolean isUnlocked);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void render(int x, int y, Minecraft mc, boolean isUnlocked);
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o){
|
||||
@@ -0,0 +1,43 @@
|
||||
package chylex.hee.mechanics.compendium.content.type;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import chylex.hee.gui.GuiKnowledgeBook;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class KnowledgeFragmentText extends KnowledgeFragment{
|
||||
private String content;
|
||||
|
||||
public KnowledgeFragmentText(int globalID){
|
||||
super(globalID);
|
||||
}
|
||||
|
||||
public KnowledgeFragmentText setContents(String text){
|
||||
this.content = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getHeight(Minecraft mc, boolean isUnlocked){
|
||||
boolean origFont = mc.fontRenderer.getUnicodeFlag();
|
||||
mc.fontRenderer.setUnicodeFlag(true);
|
||||
int h = mc.fontRenderer.listFormattedStringToWidth(getString(isUnlocked),GuiKnowledgeBook.guiPageWidth-10).size()*mc.fontRenderer.FONT_HEIGHT;
|
||||
mc.fontRenderer.setUnicodeFlag(origFont);
|
||||
return h;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void render(int x, int y, Minecraft mc, boolean isUnlocked){
|
||||
boolean origFont = mc.fontRenderer.getUnicodeFlag();
|
||||
mc.fontRenderer.setUnicodeFlag(true);
|
||||
mc.fontRenderer.drawSplitString(getString(isUnlocked),x+1,y,GuiKnowledgeBook.guiPageWidth-10,255<<24);
|
||||
mc.fontRenderer.setUnicodeFlag(origFont);
|
||||
}
|
||||
|
||||
protected String getString(boolean isUnlocked){
|
||||
return isUnlocked ? content : StringUtils.repeat('?',content.length());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package chylex.hee.mechanics.compendium.content.type;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import chylex.hee.mechanics.compendium.content.objects.IKnowledgeObjectInstance;
|
||||
import chylex.hee.mechanics.knowledge.util.IGuiItemStackRenderer;
|
||||
|
||||
public class KnowledgeObject<T extends IKnowledgeObjectInstance> implements IGuiItemStackRenderer{
|
||||
private static final int iconSize = 30;
|
||||
|
||||
private final T object;
|
||||
private final ItemStack itemToRender;
|
||||
private final String tooltip;
|
||||
private final Set<KnowledgeFragment> fragmentSet = new LinkedHashSet<>();
|
||||
private int x, y, unlockPrice;
|
||||
|
||||
public KnowledgeObject(T object){
|
||||
this(object,object.createItemStackToRender());
|
||||
}
|
||||
|
||||
public KnowledgeObject(T object, ItemStack itemToRender){
|
||||
this(object,itemToRender,itemToRender.getDisplayName());
|
||||
}
|
||||
|
||||
public KnowledgeObject(T object, String tooltip){
|
||||
this(object,object.createItemStackToRender(),tooltip);
|
||||
}
|
||||
|
||||
public KnowledgeObject(T object, ItemStack itemToRender, String tooltip){
|
||||
this.object = object;
|
||||
this.itemToRender = itemToRender;
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public KnowledgeObject setPos(int x, int y){
|
||||
this.x = x*iconSize;
|
||||
this.y = y*iconSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public KnowledgeObject setUnlockPrice(int price){
|
||||
this.unlockPrice = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getUnlockPrice(){
|
||||
return unlockPrice;
|
||||
}
|
||||
|
||||
public KnowledgeObject setFragments(KnowledgeFragment[] fragments){
|
||||
for(KnowledgeFragment fragment:fragments)this.fragmentSet.add(fragment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX(){
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY(){
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(){
|
||||
return itemToRender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip(){
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
public enum Type{
|
||||
BLOCK, ITEM, MOB
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,11 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
|
||||
|
||||
public final class CompendiumEvents{
|
||||
private static final String playerPropertyIdentifier = "HardcoreEnderExpansion~Compendium";
|
||||
|
||||
private static CompendiumEvents instance;
|
||||
|
||||
public static void register(){
|
||||
@@ -17,7 +20,9 @@ public final class CompendiumEvents{
|
||||
}
|
||||
}
|
||||
|
||||
public static final String playerPropertyIdentifier = "HardcoreEnderExpansion~Compendium";
|
||||
public static PlayerCompendiumData getPlayerData(EntityPlayer player){
|
||||
return (PlayerCompendiumData)player.getExtendedProperties(playerPropertyIdentifier);
|
||||
}
|
||||
|
||||
private CompendiumEvents(){}
|
||||
|
||||
@@ -29,4 +34,9 @@ public final class CompendiumEvents{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogin(PlayerLoggedInEvent e){
|
||||
// TODO send compendium packet
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
package chylex.hee.mechanics.compendium.events;
|
||||
import chylex.hee.gui.GuiEnderCompendium;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import chylex.hee.gui.GuiEnderCompendium;
|
||||
import chylex.hee.mechanics.compendium.player.PlayerCompendiumData;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final class CompendiumEventsClient{
|
||||
private static CompendiumEventsClient instance;
|
||||
|
||||
@@ -14,7 +19,12 @@ public final class CompendiumEventsClient{
|
||||
if (instance == null)FMLCommonHandler.instance().bus().register(instance = new CompendiumEventsClient());
|
||||
}
|
||||
|
||||
public static void loadClientData(PlayerCompendiumData data){
|
||||
instance.data = data;
|
||||
}
|
||||
|
||||
private KeyBinding keyOpenCompendium;
|
||||
private PlayerCompendiumData data;
|
||||
|
||||
private CompendiumEventsClient(){
|
||||
keyOpenCompendium = new KeyBinding("key.openCompendium",25,"Hardcore Ender Expansion");
|
||||
@@ -27,7 +37,8 @@ public final class CompendiumEventsClient{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
if (mc.inGameHasFocus && keyOpenCompendium.isPressed()){
|
||||
mc.displayGuiScreen(new GuiEnderCompendium()); // TODO temp
|
||||
if (data != null)mc.displayGuiScreen(new GuiEnderCompendium(data));
|
||||
else mc.thePlayer.addChatMessage(new ChatComponentText("Error opening Ender Compendium, server did not provide required data. Relog, wait a few seconds, pray to your favourite deity and try again!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,19 +10,29 @@ import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import chylex.hee.mechanics.compendium.content.objects.ObjectBlock.BlockMetaWrapper;
|
||||
import chylex.hee.mechanics.compendium.player.PlayerDiscoveryList.IObjectSerializer;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PlayerCompendiumData implements IExtendedEntityProperties{
|
||||
private int pointAmount;
|
||||
|
||||
private PlayerDiscoveryList<Block> discoveredBlocks = new PlayerDiscoveryList<>(new DiscoveryBlockSerializer());
|
||||
private PlayerDiscoveryList<BlockMetaWrapper> discoveredBlocks = new PlayerDiscoveryList<>(new DiscoveryBlockSerializer());
|
||||
private PlayerDiscoveryList<Item> discoveredItems = new PlayerDiscoveryList<>(new DiscoveryItemSerializer());
|
||||
private PlayerDiscoveryList<Class<? extends EntityLivingBase>> discoveryMobs = new PlayerDiscoveryList<>(new DiscoveryMobSerializer());
|
||||
|
||||
private TIntHashSet unlockedFragments = new TIntHashSet();
|
||||
|
||||
public PlayerCompendiumData(){}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public PlayerCompendiumData(NBTTagCompound nbt){
|
||||
loadNBTData(nbt);
|
||||
}
|
||||
|
||||
public int getPoints(){
|
||||
return pointAmount;
|
||||
}
|
||||
@@ -31,16 +41,16 @@ public class PlayerCompendiumData implements IExtendedEntityProperties{
|
||||
pointAmount = Math.max(0,pointAmount-amount);
|
||||
}
|
||||
|
||||
public boolean tryDiscoverBlock(Block block){
|
||||
if (discoveredBlocks.addObject(block)){
|
||||
public boolean tryDiscoverBlock(Block block, int metadata){
|
||||
if (discoveredBlocks.addObject(new BlockMetaWrapper(block,metadata))){
|
||||
// unlock discovery fragments
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean hasDiscoveredBlock(Block block){
|
||||
return discoveredBlocks.hasDiscoveredObject(block);
|
||||
public boolean hasDiscoveredBlock(Block block, int metadata){
|
||||
return discoveredBlocks.hasDiscoveredObject(new BlockMetaWrapper(block,metadata));
|
||||
}
|
||||
|
||||
public boolean tryDiscoverItem(Item item){
|
||||
@@ -90,17 +100,17 @@ public class PlayerCompendiumData implements IExtendedEntityProperties{
|
||||
|
||||
// SERIALIZERS
|
||||
|
||||
private static class DiscoveryBlockSerializer implements IObjectSerializer<Block>{
|
||||
private static class DiscoveryBlockSerializer implements IObjectSerializer<BlockMetaWrapper>{
|
||||
@Override
|
||||
public String serialize(Block object){
|
||||
UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(object);
|
||||
return identifier.modId+":"+identifier.name;
|
||||
public String serialize(BlockMetaWrapper object){
|
||||
UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(object.block);
|
||||
return identifier.modId+":"+identifier.name+":"+object.metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block deserialize(String data){
|
||||
int colonIndex = data.indexOf(":");
|
||||
return GameRegistry.findBlock(data.substring(0,colonIndex),data.substring(colonIndex+1));
|
||||
public BlockMetaWrapper deserialize(String data){
|
||||
int colonIndex = data.indexOf(":"), nextColonIndex = data.indexOf(":",colonIndex+1);
|
||||
return new BlockMetaWrapper(GameRegistry.findBlock(data.substring(0,colonIndex),data.substring(colonIndex+1,nextColonIndex)),Integer.parseInt(data.substring(nextColonIndex+1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package chylex.hee.packets.client;
|
||||
import java.io.IOException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTSizeTracker;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import chylex.hee.mechanics.compendium.events.CompendiumEvents;
|
||||
import chylex.hee.mechanics.compendium.events.CompendiumEventsClient;
|
||||
import chylex.hee.mechanics.compendium.player.PlayerCompendiumData;
|
||||
import chylex.hee.packets.AbstractClientPacket;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class C19CompendiumData extends AbstractClientPacket{
|
||||
private PlayerCompendiumData data;
|
||||
|
||||
public C19CompendiumData(){}
|
||||
|
||||
public C19CompendiumData(EntityPlayer player){
|
||||
data = CompendiumEvents.getPlayerData(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer){
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
data.saveNBTData(nbt);
|
||||
|
||||
try{
|
||||
byte[] compressed = CompressedStreamTools.compress(nbt);
|
||||
buffer.writeShort(compressed.length);
|
||||
buffer.writeBytes(compressed);
|
||||
}catch(IOException e){
|
||||
buffer.writeShort(-1);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buffer){
|
||||
short len = buffer.readShort();
|
||||
if (len == -1)return;
|
||||
|
||||
byte[] compressed = buffer.readBytes(len).array();
|
||||
|
||||
try{
|
||||
data = new PlayerCompendiumData(CompressedStreamTools.func_152457_a(compressed,new NBTSizeTracker(2097152L)));
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected void handle(EntityClientPlayerMP player){
|
||||
if (data != null)CompendiumEventsClient.loadClientData(data);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user