mirror of
https://github.com/chylex/Hardcore-Ender-Expansion.git
synced 2025-04-10 20:15:42 +02:00
Add Knowledge Note GUI, handling and generation
This commit is contained in:
parent
cf9b365c46
commit
a323a61d5e
src/main
java/chylex/hee
game/save/types/player
gui
item
packets/client
world/feature
resources/assets/hardcoreenderexpansion/lang
@ -34,8 +34,11 @@ public class LoreFile extends PlayerFile{
|
||||
|
||||
public void markAsRead(LoreTexts category, int index){
|
||||
byte[] read = readTexts.getOrDefault(category,ArrayUtils.EMPTY_BYTE_ARRAY);
|
||||
readTexts.put(category,ArrayUtils.add(read,(byte)index));
|
||||
setModified();
|
||||
|
||||
if (ArrayUtils.contains(read,(byte)index)){
|
||||
readTexts.put(category,ArrayUtils.add(read,(byte)index));
|
||||
setModified();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
52
src/main/java/chylex/hee/gui/GuiKnowledgeNote.java
Normal file
52
src/main/java/chylex/hee/gui/GuiKnowledgeNote.java
Normal file
@ -0,0 +1,52 @@
|
||||
package chylex.hee.gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import chylex.hee.gui.helpers.GuiHelper;
|
||||
import chylex.hee.mechanics.compendium.handlers.CompendiumPageHandler;
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiKnowledgeNote extends GuiScreen{
|
||||
private final String translatedText;
|
||||
private final int addedPoints;
|
||||
|
||||
public GuiKnowledgeNote(String unlocalized, int addedPoints){
|
||||
this.translatedText = I18n.format(unlocalized);
|
||||
this.addedPoints = addedPoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
buttonList.add(new GuiButtonExt(1,width/2-75,height/2+92,150,20,I18n.format("gui.done")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button){
|
||||
if (button.id == 1)mc.setIngameFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTickTime){
|
||||
GL11.glColor4f(1F,1F,1F,1F);
|
||||
mc.getTextureManager().bindTexture(CompendiumPageHandler.texPage);
|
||||
drawTexturedModalRect((width-CompendiumPageHandler.pageWidth)/2,(height-CompendiumPageHandler.pageHeight)/2-20,0,0,CompendiumPageHandler.pageWidth,CompendiumPageHandler.pageHeight);
|
||||
|
||||
GuiHelper.renderUnicodeString(translatedText,(width-CompendiumPageHandler.pageWidth)/2+18,(height-CompendiumPageHandler.pageHeight)/2+1,CompendiumPageHandler.innerWidth,255<<24);
|
||||
|
||||
if (addedPoints > 0){
|
||||
boolean origFont = fontRendererObj.getUnicodeFlag();
|
||||
fontRendererObj.setUnicodeFlag(true);
|
||||
|
||||
String text = I18n.format("compendium.notePoints").replace("$",String.valueOf(addedPoints));
|
||||
GuiHelper.renderUnicodeString(text,(width-fontRendererObj.getStringWidth(text))/2,(height/2)+55,CompendiumPageHandler.innerWidth,255<<24|(32<<16)|(32<<8)|32);
|
||||
|
||||
fontRendererObj.setUnicodeFlag(origFont);
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX,mouseY,partialTickTime);
|
||||
}
|
||||
}
|
@ -1,13 +1,18 @@
|
||||
package chylex.hee.item;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import chylex.hee.game.save.SaveData;
|
||||
import chylex.hee.game.save.types.player.LoreFile;
|
||||
import chylex.hee.mechanics.compendium.content.LoreTexts;
|
||||
import chylex.hee.mechanics.compendium.events.CompendiumEvents;
|
||||
import chylex.hee.packets.PacketPipeline;
|
||||
import chylex.hee.packets.client.C03KnowledgeNote;
|
||||
import chylex.hee.packets.client.C19CompendiumData;
|
||||
import chylex.hee.system.util.ItemUtil;
|
||||
import chylex.hee.world.loot.interfaces.IItemPostProcessor;
|
||||
@ -18,20 +23,36 @@ public class ItemKnowledgeNote extends Item{
|
||||
public ItemKnowledgeNote(){
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack is, World world, Entity entity, int slot, boolean isHeld){
|
||||
if (!world.isRemote && !is.hasTagCompound())setRandomNote(is,itemRand,5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player){
|
||||
world.playSoundAtEntity(player,"hardcoreenderexpansion:player.random.pageflip",1.5F,0.5F*((player.getRNG().nextFloat()-player.getRNG().nextFloat())*0.7F+1.8F));
|
||||
if (!world.isRemote)player.worldObj.playSoundAtEntity(player,"hardcoreenderexpansion:player.random.pageflip",1.5F,0.5F*((world.rand.nextFloat()-world.rand.nextFloat())*0.7F+1.8F));
|
||||
|
||||
if (!world.isRemote && is.hasTagCompound()){
|
||||
CompendiumEvents.getPlayerData(player).offsetPoints(is.getTagCompound().getByte("pts"));
|
||||
PacketPipeline.sendToPlayer(player,new C19CompendiumData(player));
|
||||
--is.stackSize;
|
||||
NBTTagCompound nbt = is.getTagCompound();
|
||||
int added = nbt.getByte("notePts");
|
||||
|
||||
if (nbt.getByte("notePts") > 0){
|
||||
CompendiumEvents.getPlayerData(player).offsetPoints(is.getTagCompound().getByte("notePts"));
|
||||
PacketPipeline.sendToPlayer(player,new C19CompendiumData(player));
|
||||
nbt.setByte("notePts",(byte)0);
|
||||
}
|
||||
|
||||
if (nbt.hasKey("noteCat")){
|
||||
LoreTexts category = LoreTexts.fromTitle(nbt.getString("noteCat"));
|
||||
int index;
|
||||
|
||||
if (nbt.hasKey("noteInd")){
|
||||
index = nbt.getByte("noteInd");
|
||||
SaveData.player(player,LoreFile.class).markAsRead(category,index);
|
||||
}
|
||||
else{
|
||||
index = SaveData.player(player,LoreFile.class).getRandomTextIndex(category,world.rand);
|
||||
nbt.setByte("noteInd",(byte)index);
|
||||
}
|
||||
|
||||
PacketPipeline.sendToPlayer(player,new C03KnowledgeNote(category,index,added));
|
||||
}
|
||||
}
|
||||
|
||||
return is;
|
||||
@ -40,15 +61,20 @@ public class ItemKnowledgeNote extends Item{
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack is, EntityPlayer player, List textLines, boolean showAdvancedInfo){
|
||||
if (is.hasTagCompound())textLines.add(is.getTagCompound().getByte("pts")+" Knowledge Points");
|
||||
NBTTagCompound nbt = ItemUtil.getTagRoot(is,false);
|
||||
if (nbt.hasKey("noteCat"))textLines.add(I18n.format("ec.note."+nbt.getString("noteCat")+".title"));
|
||||
|
||||
if (nbt.hasKey("notePts"))textLines.add(nbt.getByte("notePts") > 0 ? I18n.format("item.knowledgeNote.pts").replace("$",String.valueOf(nbt.getByte("notePts"))) : I18n.format("item.knowledgeNote.used"));
|
||||
else if (nbt.hasKey("pts"))textLines.add(I18n.format("item.knowledgeNote.useless"));
|
||||
}
|
||||
|
||||
public static IItemPostProcessor createNoteProcessor(final int multiplier){
|
||||
return (is, rand) -> { return ItemKnowledgeNote.setRandomNote(is,rand,multiplier); };
|
||||
public static IItemPostProcessor createNoteProcessor(final LoreTexts category, final int minMultiplier, final int maxMultiplier){
|
||||
return (is, rand) -> setNoteInfo(is,rand,category,minMultiplier+rand.nextInt(1+maxMultiplier-minMultiplier));
|
||||
}
|
||||
|
||||
public static ItemStack setRandomNote(ItemStack is, Random rand, int multiplier){
|
||||
ItemUtil.getTagRoot(is,true).setByte("pts",(byte)((rand.nextInt(4)*rand.nextInt(4)+rand.nextInt(3)+2)*multiplier));
|
||||
public static final ItemStack setNoteInfo(ItemStack is, Random rand, LoreTexts category, int multiplier){
|
||||
ItemUtil.getTagRoot(is,true).setByte("notePts",(byte)(5*multiplier));
|
||||
ItemUtil.getTagRoot(is,true).setString("noteCat",category.getTitle());
|
||||
return is;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package chylex.hee.packets.client;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import chylex.hee.gui.GuiKnowledgeNote;
|
||||
import chylex.hee.mechanics.compendium.content.LoreTexts;
|
||||
import chylex.hee.packets.AbstractClientPacket;
|
||||
import chylex.hee.system.collections.CollectionUtil;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class C03KnowledgeNote extends AbstractClientPacket{
|
||||
private LoreTexts category;
|
||||
private int index, points;
|
||||
|
||||
public C03KnowledgeNote(){}
|
||||
|
||||
public C03KnowledgeNote(LoreTexts category, int index, int points){
|
||||
this.category = category;
|
||||
this.index = index;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer){
|
||||
buffer.writeByte(category.ordinal()).writeByte(index).writeShort(points);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buffer){
|
||||
category = CollectionUtil.get(LoreTexts.values(),buffer.readByte()).orElse(LoreTexts.UNKNOWN);
|
||||
index = buffer.readByte();
|
||||
points = buffer.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected void handle(EntityClientPlayerMP player){
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiKnowledgeNote(category.getUnlocalizedName(index),points));
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ import chylex.hee.game.save.SaveData;
|
||||
import chylex.hee.game.save.types.global.StrongholdFile;
|
||||
import chylex.hee.init.ItemList;
|
||||
import chylex.hee.item.ItemKnowledgeNote;
|
||||
import chylex.hee.mechanics.compendium.content.LoreTexts;
|
||||
import chylex.hee.system.abstractions.Meta;
|
||||
import chylex.hee.system.abstractions.Meta.BlockColor;
|
||||
import chylex.hee.system.abstractions.Pos;
|
||||
@ -91,7 +92,7 @@ public class WorldGenStronghold implements IWorldGenerator{
|
||||
lootGeneral.addLoot(Items.glass_bottle).setAmount(1).setWeight(22);
|
||||
lootGeneral.addLoot(Items.potionitem).setAmount(1).setWeight(22);
|
||||
lootGeneral.addLoot(Items.diamond).setAmount(1,2).setWeight(14);
|
||||
lootGeneral.addPostProcessor(ItemKnowledgeNote.createNoteProcessor(1)); // TODO update
|
||||
lootGeneral.addPostProcessor(ItemKnowledgeNote.createNoteProcessor(LoreTexts.STRONGHOLD,1,2));
|
||||
|
||||
lootLibrary.addLoot(Items.paper).setAmount(1,3).setWeight(50);
|
||||
lootLibrary.addLoot(Items.book).setAmount(1,2).setWeight(45);
|
||||
@ -99,7 +100,7 @@ public class WorldGenStronghold implements IWorldGenerator{
|
||||
lootLibrary.addLoot(ItemList.ancient_dust).setAmount(1,2).setWeight(36);
|
||||
lootLibrary.addLoot(Items.compass).setAmount(1).setWeight(22);
|
||||
lootLibrary.addLoot(Items.map).setAmount(1).setWeight(20);
|
||||
lootLibrary.addPostProcessor(ItemKnowledgeNote.createNoteProcessor(1)); // TODO update
|
||||
lootLibrary.addPostProcessor(ItemKnowledgeNote.createNoteProcessor(LoreTexts.STRONGHOLD,1,2));
|
||||
}
|
||||
|
||||
public static Optional<ChunkCoordIntPair> findNearestStronghold(int chunkX, int chunkZ, World world){
|
||||
|
@ -139,6 +139,9 @@ item.curseAmulet.name=Curse Amulet
|
||||
item.bucketEnderGoo.name=Ender Goo Bucket
|
||||
item.knowledgeNote.name=Knowledge Note
|
||||
item.knowledgeNote.bacon.name=Bacon of Knowledge
|
||||
item.knowledgeNote.pts=$ Knowledge Points
|
||||
item.knowledgeNote.used=Used
|
||||
item.knowledgeNote.useless=Useless (sorry)
|
||||
item.enhancedBrewingStand.name=Enhanced Brewing Stand
|
||||
item.scorchingPickaxe.name=Scorching Pickaxe
|
||||
item.scorchingPickaxe.bacon.name=Scorching Bacon
|
||||
@ -286,6 +289,7 @@ container.amuletOfRecovery=Amulet of Recovery
|
||||
|
||||
enhancements.none=No Enhancements
|
||||
|
||||
compendium.notePoints=+$ Knowledge Points
|
||||
compendium.discoveredObject=Unlocked new Knowledge Object
|
||||
compendium.cannotBuy=Cannot buy this object
|
||||
compendium.nonBuyable=The fragment has to be purchased elsewhere
|
||||
|
Loading…
Reference in New Issue
Block a user