1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion.git synced 2025-04-10 20:15:42 +02:00

Very basic Charm Pouch

This commit is contained in:
chylex 2014-07-29 20:36:11 +02:00
parent 6cdcd66d0d
commit 49a58d0780
22 changed files with 253 additions and 24 deletions

Binary file not shown.

BIN
src/_/charm_pouch.png Normal file

Binary file not shown.

After

(image error) Size: 3.7 KiB

View File

@ -0,0 +1,125 @@
package chylex.hee.gui;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.tuple.Pair;
import chylex.hee.item.ItemCharmPouch;
import chylex.hee.item.ItemList;
import chylex.hee.mechanics.charms.CharmRecipe;
import chylex.hee.mechanics.charms.CharmType;
import chylex.hee.mechanics.charms.RuneType;
public class ContainerCharmPouch extends Container{
private final EntityPlayer player;
private final ItemStack pouch;
private final IInventory charmInv = new InventoryBasic("container.charmPouch",false,3);
private final IInventory runeInv = new InventoryBasic("container.runeCrafting",false,5);
private final IInventory runeResultInv = new InventoryBasic("container.runeCrafting",false,1);
public ContainerCharmPouch(EntityPlayer player){
this.player = player;
pouch = player.getCurrentEquippedItem();
for(int a = 0; a < 3; a++){
addSlotToContainer(new SlotBasicItem(charmInv,a,39,20+a*20,ItemList.charm,1));
}
ItemStack[] charms = ItemCharmPouch.getPouchCharms(pouch);
for(int a = 0; a < Math.min(charmInv.getSizeInventory(),charms.length); a++)charmInv.setInventorySlotContents(a,charms[a]);
addSlotToContainer(new SlotCharmPouchRune(runeInv,this,0,122,18,ItemList.rune,16));
addSlotToContainer(new SlotCharmPouchRune(runeInv,this,1,98,38,ItemList.rune,16));
addSlotToContainer(new SlotCharmPouchRune(runeInv,this,2,146,38,ItemList.rune,16));
addSlotToContainer(new SlotCharmPouchRune(runeInv,this,3,109,63,ItemList.rune,16));
addSlotToContainer(new SlotCharmPouchRune(runeInv,this,4,135,63,ItemList.rune,16));
addSlotToContainer(new SlotCharmPouchRuneResult(runeResultInv,runeInv,this,0,122,41));
for(int a = 0; a < 3; a++){
for(int b = 0; b < 9; ++b)addSlotToContainer(new Slot(player.inventory,b+a*9+9,8+b*18,94+a*18));
}
for(int a = 0; a < 9; a++)addSlotToContainer(new Slot(player.inventory,a,8+a*18,152));
}
@Override
public void detectAndSendChanges(){
super.detectAndSendChanges();
if (!player.worldObj.isRemote && !ItemStack.areItemStacksEqual(player.getCurrentEquippedItem(),pouch))player.closeScreen();
}
@Override
public void onCraftMatrixChanged(IInventory inventory){
if (inventory == runeInv){
runeResultInv.setInventorySlotContents(0,null);
List<RuneType> runes = new ArrayList<RuneType>(5);
for(int a = 0; a < 5; a++){
ItemStack rune = runeInv.getStackInSlot(a);
if (rune != null){
int damage = rune.getItemDamage();
if (damage >= 0 && damage < RuneType.values.length)runes.add(RuneType.values[damage]);
}
}
if (runes.size() >= 3){
Pair<CharmType,CharmRecipe> charm = CharmType.findRecipe(runes.toArray(new RuneType[runes.size()]));
if (charm != null)runeResultInv.setInventorySlotContents(0,new ItemStack(ItemList.charm,1,charm.getRight().id));
}
}
}
@Override
public void onContainerClosed(EntityPlayer player){
super.onContainerClosed(player);
for(int a = 0; a < 5; a++){
ItemStack is = runeInv.getStackInSlot(a);
if (is != null)player.dropPlayerItemWithRandomChoice(is,false);
}
runeResultInv.setInventorySlotContents(0,null);
ItemCharmPouch.setPouchCharms(player.getCurrentEquippedItem(),new ItemStack[]{ charmInv.getStackInSlot(0), charmInv.getStackInSlot(1), charmInv.getStackInSlot(2) });
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotId){
ItemStack is = null;
Slot slot = (Slot)inventorySlots.get(slotId);
if (slot != null && slot.getHasStack()){
ItemStack is2 = slot.getStack();
is = is2.copy();
if (slotId < 9){
if (!mergeItemStack(is2,9,inventorySlots.size(),true))return null;
}
else{
if (is2.getItem() == ItemList.charm){
if (!mergeItemStack(is2,0,3,false))return null;
}
else if (is2.getItem() == ItemList.rune){
if (!mergeItemStack(is2,3,8,false))return null;
}
}
if (is2.stackSize == 0)slot.putStack(null);
else slot.onSlotChanged();
}
return is;
}
@Override
public boolean canInteractWith(EntityPlayer player){
return true;
}
}

View File

@ -73,10 +73,7 @@ public class ContainerDecompositionTable extends Container{
ItemStack is2 = slot.getStack();
is = is2.copy();
if (slotId == 1){
if (!mergeItemStack(is2,11,inventorySlots.size(),true))return null;
}
else if (slotId < 11){
if (slotId < 11){
if (!mergeItemStack(is2,11,inventorySlots.size(),true))return null;
}
else{

View File

@ -0,0 +1,38 @@
package chylex.hee.gui;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
@SideOnly(Side.CLIENT)
public class GuiCharmPouch extends GuiContainer{
private static final ResourceLocation guiResource = new ResourceLocation("hardcoreenderexpansion:textures/gui/charm_pouch.png");
public GuiCharmPouch(EntityPlayer player){
super(new ContainerCharmPouch(player));
ySize = 176;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY){
String s = I18n.format("container.charmPouch");
fontRendererObj.drawString(s,(xSize>>2)-(fontRendererObj.getStringWidth(s)>>1)+1,6,4210752);
s = I18n.format("container.runeCrafting");
fontRendererObj.drawString(s,3*(xSize>>2)-(fontRendererObj.getStringWidth(s)>>1)-1,6,4210752);
fontRendererObj.drawString(I18n.format("container.inventory"),8,ySize-96+2,4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTickTime, int mouseX, int mouseY){
GL11.glColor4f(1F,1F,1F,1F);
mc.getTextureManager().bindTexture(guiResource);
int guiX = (width-xSize)>>1, guiY = (height-ySize)>>1;
drawTexturedModalRect(guiX,guiY,0,0,xSize,ySize);
}
}

View File

@ -11,7 +11,7 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiDecompositionTable extends GuiContainer{
private static ResourceLocation guiResource = new ResourceLocation("hardcoreenderexpansion:textures/gui/decomposition_table.png");
private static final ResourceLocation guiResource = new ResourceLocation("hardcoreenderexpansion:textures/gui/decomposition_table.png");
private TileEntityDecompositionTable decompositionTable;

View File

@ -14,7 +14,7 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiEnergyExtractionTable extends GuiContainer{
private static ResourceLocation guiResource = new ResourceLocation("hardcoreenderexpansion:textures/gui/energy_extraction_table.png");
private static final ResourceLocation guiResource = new ResourceLocation("hardcoreenderexpansion:textures/gui/energy_extraction_table.png");
private TileEntityEnergyExtractionTable energyExtractionTable;

View File

@ -6,7 +6,7 @@ import chylex.hee.tileentity.TileEntityEnergyExtractionTable;
import chylex.hee.tileentity.TileEntityEnhancedBrewingStand;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler{
public final class GuiHandler implements IGuiHandler{
public static GuiHandler instance = new GuiHandler();
@Override
@ -16,7 +16,9 @@ public class GuiHandler implements IGuiHandler{
case 2: return new ContainerDecompositionTable(player.inventory,(TileEntityDecompositionTable)world.getTileEntity(x,y,z));
case 3: return new ContainerEnergyExtractionTable(player.inventory,(TileEntityEnergyExtractionTable)world.getTileEntity(x,y,z));
case 4: return new ContainerEndPowderEnhancements(player.inventory);
case 5: return new ContainerCharmPouch(player);
}
return null;
}
@ -28,7 +30,11 @@ public class GuiHandler implements IGuiHandler{
case 2: return new GuiDecompositionTable(player.inventory,(TileEntityDecompositionTable)world.getTileEntity(x,y,z));
case 3: return new GuiEnergyExtractionTable(player.inventory,(TileEntityEnergyExtractionTable)world.getTileEntity(x,y,z));
case 4: return new GuiEndPowderEnhancements(player.inventory);
case 5: return new GuiCharmPouch(player);
}
return null;
}
private GuiHandler(){}
}

View File

@ -0,0 +1,19 @@
package chylex.hee.gui;
import chylex.hee.item.ItemList;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
class SlotCharmPouchRune extends SlotBasicItem{
private final ContainerCharmPouch pouchContainer;
public SlotCharmPouchRune(IInventory inv, ContainerCharmPouch pouchContainer, int id, int x, int z, Item validItem, int stackLimit){
super(inv,id,x,z,ItemList.rune,16);
this.pouchContainer = pouchContainer;
}
@Override
public void onSlotChanged(){
super.onSlotChanged();
pouchContainer.onCraftMatrixChanged(inventory);
}
}

View File

@ -0,0 +1,33 @@
package chylex.hee.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class SlotCharmPouchRuneResult extends Slot{
private final IInventory runeInv;
private final ContainerCharmPouch pouchContainer;
public SlotCharmPouchRuneResult(IInventory inv, IInventory runeInv, ContainerCharmPouch pouchContainer, int slot, int x, int y){
super(inv,slot,x,y);
this.runeInv = runeInv;
this.pouchContainer = pouchContainer;
}
@Override
public boolean isItemValid(ItemStack is){
return false;
}
@Override
public void onPickupFromSlot(EntityPlayer player, ItemStack is){
super.onPickupFromSlot(player,is);
for(int a = 0; a < runeInv.getSizeInventory(); a++){
ItemStack slotIS = runeInv.getStackInSlot(a);
if (slotIS != null && --slotIS.stackSize == 0)runeInv.setInventorySlotContents(a,null);
}
pouchContainer.onCraftMatrixChanged(runeInv);
}
}

View File

@ -12,7 +12,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemCharm extends Item{
private static final byte iconsBackAmount = 17, iconsForeAmount = 8;
private static final byte iconsBackAmount = 17, iconsForeAmount = 10;
@SideOnly(Side.CLIENT)
private IIcon[] iconArrayBack, iconArrayFore;

View File

@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import chylex.hee.HardcoreEnderExpansion;
import chylex.hee.mechanics.charms.CharmPouchHandler;
import chylex.hee.mechanics.charms.CharmPouchInfo;
import cpw.mods.fml.relauncher.Side;
@ -23,8 +24,15 @@ public class ItemCharmPouch extends Item{
@Override
public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player){
CharmPouchHandler.setActivePouch(player,is);
(is.stackTagCompound == null ? is.stackTagCompound = new NBTTagCompound() : is.stackTagCompound).setBoolean("isPouchActive",true);
if (world.isRemote)return is;
if (player.isSneaking()){
CharmPouchInfo activePouch = CharmPouchHandler.getActivePouch(player);
CharmPouchHandler.setActivePouch(player,activePouch != null && activePouch.pouchID == getPouchID(is) ? null : is);
(is.stackTagCompound == null ? is.stackTagCompound = new NBTTagCompound() : is.stackTagCompound).setBoolean("isPouchActive",true);
}
else player.openGui(HardcoreEnderExpansion.instance,5,world,0,0,0);
return is;
}
@ -61,7 +69,9 @@ public class ItemCharmPouch extends Item{
NBTTagCompound nbt = pouch.stackTagCompound != null ? pouch.stackTagCompound : (pouch.stackTagCompound = new NBTTagCompound());
NBTTagList tagCharms = new NBTTagList();
for(ItemStack charm:charms)tagCharms.appendTag(charm.writeToNBT(new NBTTagCompound()));
for(ItemStack charm:charms){
if (charm != null)tagCharms.appendTag(charm.writeToNBT(new NBTTagCompound()));
}
nbt.setTag("pouchCharms",tagCharms);
}

View File

@ -138,9 +138,11 @@ public final class ItemList{
.setUnlocalizedName("charmPouch").setTextureName("hardcoreenderexpansion:charm_pouch");
rune = new ItemRune()
.setMaxStackSize(16)
.setUnlocalizedName("rune").setTextureName("hardcoreenderexpansion:rune");
charm = new ItemCharm()
.setMaxStackSize(1)
.setUnlocalizedName("charm").setTextureName("hardcoreenderexpansion:charm");
corporeal_mirage_orb = new ItemCorporealMirageOrb()

View File

@ -31,7 +31,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import cpw.mods.fml.relauncher.Side;
final class CharmEvents{
public final class CharmEvents{
private static final float DEFAULT_PLAYER_SPEED = 0.1F;
private static float[] getProp(EntityPlayer player, String prop){

View File

@ -21,7 +21,8 @@ public final class CharmPouchHandler{
}
public static void setActivePouch(EntityPlayer player, ItemStack is){
instance.activePouchIDs.put(player.getGameProfile().getId(),new CharmPouchInfo(is));
if (is == null)instance.activePouchIDs.remove(player.getGameProfile().getId());
else instance.activePouchIDs.put(player.getGameProfile().getId(),new CharmPouchInfo(is));
instance.refresh = true;
}
@ -38,7 +39,7 @@ public final class CharmPouchHandler{
@SubscribeEvent
public void onServerTick(ServerTickEvent e){
if (e.phase != Phase.START || !refresh)return;
if (e.phase != Phase.END || !refresh)return;
if (!isHandlerActive && !activePouchIDs.isEmpty()){
isHandlerActive = true;

View File

@ -19,8 +19,9 @@ public class CharmRecipe{
}
public CharmRecipe rune(RuneType rune, int amount){
if (runes.containsKey(rune))runeAmount -= runes.remove(rune);
runes.put(rune,(byte)amount);
runeAmount = (byte)runes.size();
runeAmount += amount;
return this;
}

View File

@ -35,7 +35,7 @@ public enum CharmType{ // TODO implement the rest
new CharmRecipe(14).rune(MAGIC,5).prop("exp",1.30F)
}, "lit,+$perc-1,exp$s$lang,experience"),
EQUALITY(16, 0, new CharmRecipe[]{
EQUALITY(16, 9, new CharmRecipe[]{
new CharmRecipe(18).rune(POWER).rune(AGILITY).rune(VIGOR).rune(DEFENSE).rune(MAGIC).prop("dmg",1.08F).prop("spd",1.05F).prop("regenspd",0.94F).prop("reducedmg",0.03F).prop("exp",1.03F)
}, "lit,+$perc-1,dmg$s$lang,damage$nl$lit,+$perc-1,spd$s$lang,speed$nl$lit,+$perc1-,regenspd$s$lang,regen$nl$lit,-$perc,reducedmg$s$lang,damagetaken$nl$lit,+$perc-1,exp$s$lang,experience"),
@ -99,7 +99,7 @@ public enum CharmType{ // TODO implement the rest
new CharmRecipe(50).rune(AGILITY,4).rune(DEFENSE).prop("fallblocks",6)
}, "lit,+$int,fallblocks$s$lang,blocks"),
HASTE(1, 0, new CharmRecipe[]{
HASTE(1, 8, new CharmRecipe[]{
new CharmRecipe(51).rune(AGILITY,2).rune(VOID).prop("breakspd",1.10F),
new CharmRecipe(52).rune(AGILITY,3).rune(VOID).prop("breakspd",1.18F),
new CharmRecipe(53).rune(AGILITY,4).rune(VOID).prop("breakspd",1.25F)
@ -114,7 +114,7 @@ public enum CharmType{ // TODO implement the rest
new CharmRecipe(59).rune(POWER,3).rune(AGILITY,3).prop("critchance",0.15F).prop("critdmg",2.00F)
}, "perc,critchance$s$lang,chanceto$s$lang,deal$s$perc,critdmg$s$lang,damage"),
SECOND_DURABILITY(12, 0, new CharmRecipe[]{
SECOND_DURABILITY(12, 8, new CharmRecipe[]{
new CharmRecipe(60).rune(VIGOR).rune(MAGIC).rune(VOID).prop("recdurabilitychance",0.28F).prop("recdurabilityamt",0.10F),
new CharmRecipe(61).rune(VIGOR,2).rune(MAGIC).rune(VOID).prop("recdurabilitychance",0.25F).prop("recdurabilityamt",0.18F),
new CharmRecipe(62).rune(VIGOR,3).rune(MAGIC).rune(VOID).prop("recdurabilitychance",0.22F).prop("recdurabilityamt",0.25F),

View File

@ -20,17 +20,12 @@ public class IslandBiomeBurningMountains extends IslandBiomeBase{
super(biomeID,knowledgeRegistration);
contentVariations.add(SCORCHING);
contentVariations.add(MINE);
// contentVariations.add(MINE); // TODO postponed
getSpawnEntries(SCORCHING).addAll(new SpawnEntry[]{
new SpawnEntry(EntityMobFireGolem.class,14,10),
new SpawnEntry(EntityMobScorchingLens.class,10,6)
});
getSpawnEntries(MINE).addAll(new SpawnEntry[]{ // TODO temporary
new SpawnEntry(EntityMobFireGolem.class,14,10),
new SpawnEntry(EntityMobScorchingLens.class,10,6)
});
}
@Override

View File

@ -144,6 +144,8 @@ container.enhancedBrewing=Enhanced Brewing Stand
container.decompositionTable=Decomposition Table
container.energyExtractionTable=Energy Extraction Table
container.endPowderEnhancements=End Powder Enhancements
container.charmPouch=Charm Pouch
container.runeCrafting=Rune Crafting
achievement.theMoreYouKnow=The more you know
achievement.theMoreYouKnow.desc=Craft an Ender Compendium

Binary file not shown.

After

(image error) Size: 3.7 KiB

Binary file not shown.

After

(image error) Size: 2.9 KiB

Binary file not shown.

After

(image error) Size: 2.8 KiB