diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-25 19:58:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-25 19:58:55 +0200 |
commit | 0618db983f399da0556aae55179906504100a663 (patch) | |
tree | 56222b0bd035f94386bb26586babe432b4a70304 /src/main/java/kubatech/loaders/item | |
parent | 6a2b3f3dea2071b4c459106496621c655df98e6c (diff) | |
download | GT5-Unofficial-0618db983f399da0556aae55179906504100a663.tar.gz GT5-Unofficial-0618db983f399da0556aae55179906504100a663.tar.bz2 GT5-Unofficial-0618db983f399da0556aae55179906504100a663.zip |
Add Secret Tea collection (#10)
* Licensing stuff
* Turbo Legendary Secret Tea Collection
* Turbo Legendary Secret Tea Collection
*
Diffstat (limited to 'src/main/java/kubatech/loaders/item')
-rw-r--r-- | src/main/java/kubatech/loaders/item/ItemProxy.java | 84 | ||||
-rw-r--r-- | src/main/java/kubatech/loaders/item/KubaItems.java | 145 | ||||
-rw-r--r-- | src/main/java/kubatech/loaders/item/items/Tea.java | 193 | ||||
-rw-r--r-- | src/main/java/kubatech/loaders/item/items/TeaUltimate.java | 67 |
4 files changed, 489 insertions, 0 deletions
diff --git a/src/main/java/kubatech/loaders/item/ItemProxy.java b/src/main/java/kubatech/loaders/item/ItemProxy.java new file mode 100644 index 0000000000..67491a0ba8 --- /dev/null +++ b/src/main/java/kubatech/loaders/item/ItemProxy.java @@ -0,0 +1,84 @@ +/* + * KubaTech - Gregtech Addon + * Copyright (C) 2022 kuba6000 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <https://www.gnu.org/licenses/>. + * + */ + +package kubatech.loaders.item; + +import java.util.List; +import kubatech.Tags; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +public class ItemProxy { + private final String unlocalizedName; + private final String texturepath; + private IIcon icon; + private int itemID; + + public ItemProxy(String unlocalizedName, String texture) { + this.unlocalizedName = "item.kubaitem." + unlocalizedName; + texturepath = Tags.MODID + ":" + texture; + } + + public void ItemInit(int index) { + itemID = index; + } + + public String getUnlocalizedName() { + return unlocalizedName; + } + + public String getDisplayName(ItemStack stack) { + return StatCollector.translateToLocal(this.unlocalizedName + ".name").trim(); + } + + public void registerIcon(IIconRegister iconRegister) { + icon = iconRegister.registerIcon(texturepath); + } + + public IIcon getIcon() { + return icon; + } + + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) {} + + public void onUpdate( + ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, boolean p_77663_5_) {} + + public EnumAction getItemUseAction(ItemStack p_77661_1_) { + return EnumAction.none; + } + + public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) { + return p_77659_1_; + } + + public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_) { + return p_77654_1_; + } + + public int getMaxItemUseDuration() { + return 0; + } +} diff --git a/src/main/java/kubatech/loaders/item/KubaItems.java b/src/main/java/kubatech/loaders/item/KubaItems.java new file mode 100644 index 0000000000..fdc38ec0ba --- /dev/null +++ b/src/main/java/kubatech/loaders/item/KubaItems.java @@ -0,0 +1,145 @@ +/* + * KubaTech - Gregtech Addon + * Copyright (C) 2022 kuba6000 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <https://www.gnu.org/licenses/>. + * + */ + +package kubatech.loaders.item; + +import static kubatech.kubatech.KT; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.HashMap; +import java.util.List; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumAction; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +public class KubaItems extends Item { + private static final HashMap<Integer, ItemProxy> items = new HashMap<>(); + private static int idCounter = 0; + + public KubaItems() { + this.setMaxDamage(0); + this.setHasSubtypes(true); + this.setCreativeTab(KT); + this.setUnlocalizedName("kubaitems"); + } + + public ItemStack registerProxyItem(ItemProxy item) { + items.put(idCounter, item); + item.ItemInit(idCounter); + return new ItemStack(this, 1, idCounter++); + } + + private ItemProxy getItem(ItemStack stack) { + return items.get(stack.getItemDamage()); + } + + private ItemProxy getItem(int damage) { + return items.get(damage); + } + + @Override + public boolean onItemUse( + ItemStack p_77648_1_, + EntityPlayer p_77648_2_, + World p_77648_3_, + int p_77648_4_, + int p_77648_5_, + int p_77648_6_, + int p_77648_7_, + float p_77648_8_, + float p_77648_9_, + float p_77648_10_) { + return false; + } + + @Override + public EnumAction getItemUseAction(ItemStack p_77661_1_) { + return getItem(p_77661_1_).getItemUseAction(p_77661_1_); + } + + @Override + public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) { + return getItem(p_77659_1_).onItemRightClick(p_77659_1_, p_77659_2_, p_77659_3_); + } + + @Override + public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_) { + return getItem(p_77654_1_).onEaten(p_77654_1_, p_77654_2_, p_77654_3_); + } + + @Override + public int getMaxItemUseDuration(ItemStack p_77626_1_) { + return getItem(p_77626_1_).getMaxItemUseDuration(); + } + + @Override + public int getMetadata(int p_77647_1_) { + return p_77647_1_; + } + + @Override + public String getUnlocalizedName() { + return super.getUnlocalizedName(); + } + + @Override + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { + getItem(p_77624_1_).addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); + } + + @Override + public String getUnlocalizedName(ItemStack p_77667_1_) { + return getItem(p_77667_1_).getUnlocalizedName(); + } + + @Override + public String getItemStackDisplayName(ItemStack p_77653_1_) { + return getItem(p_77653_1_).getDisplayName(p_77653_1_); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerIcons(IIconRegister p_94581_1_) { + items.values().forEach(t -> t.registerIcon(p_94581_1_)); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIconFromDamage(int damage) { + return getItem(damage).getIcon(); + } + + @Override + public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_) { + for (int i = 0; i < items.size(); i++) p_150895_3_.add(new ItemStack(p_150895_1_, 1, i)); + } + + @Override + public void onUpdate( + ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, boolean p_77663_5_) { + getItem(p_77663_1_).onUpdate(p_77663_1_, p_77663_2_, p_77663_3_, p_77663_4_, p_77663_5_); + } +} diff --git a/src/main/java/kubatech/loaders/item/items/Tea.java b/src/main/java/kubatech/loaders/item/items/Tea.java new file mode 100644 index 0000000000..d9f39bc06f --- /dev/null +++ b/src/main/java/kubatech/loaders/item/items/Tea.java @@ -0,0 +1,193 @@ +/* + * KubaTech - Gregtech Addon + * Copyright (C) 2022 kuba6000 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <https://www.gnu.org/licenses/>. + * + */ + +package kubatech.loaders.item.items; + +import java.util.LinkedList; +import java.util.List; +import kubatech.api.utils.ModUtils; +import kubatech.loaders.ItemLoader; +import kubatech.loaders.item.ItemProxy; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.stats.Achievement; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.AchievementPage; + +public class Tea extends ItemProxy { + protected static TeaPage teapage; + protected static LinkedList<Achievement> achievements; + protected Achievement achievement; + private final String achievementname; + + public Tea(String unlocalizedName) { + super("teacollection." + unlocalizedName, "teacollection/" + unlocalizedName); + achievementname = "teacollection." + unlocalizedName; + } + + private static final int[][] achievement_poses = new int[][] { + {0, 0}, + {2, 0}, + {3, 1}, + {4, 2}, + {4, 4}, + {3, 5}, + {2, 6}, + {0, 6}, + {-1, 5}, + {-2, 4}, + {-2, 2}, + {-1, 1}, + {1, 3} + }; + + @Override + public void ItemInit(int index) { + super.ItemInit(index); + if (teapage == null) { + teapage = new TeaPage(); + AchievementPage.registerAchievementPage(teapage); + achievements = teapage.getAchievementsOriginal(); + } + achievements.add( + achievement = new Achievement( + achievementname, + achievementname, + achievement_poses[index][0], + achievement_poses[index][1], + new ItemStack(ItemLoader.kubaitems, 1, index), + null) + .registerStat()); + } + + @Override + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { + if (p_77624_1_.stackTagCompound != null + && p_77624_1_.stackTagCompound.hasKey("TeaOwner") + && !p_77624_1_ + .stackTagCompound + .getString("TeaOwner") + .equals(p_77624_2_.getUniqueID().toString())) { + p_77624_3_.add(EnumChatFormatting.GRAY + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + + StatCollector.translateToLocal("item.notyours")); + return; + } + p_77624_3_.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("item.fromcollection")); + p_77624_3_.add(EnumChatFormatting.GRAY + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + "" + + EnumChatFormatting.UNDERLINE + StatCollector.translateToLocal("item.teacollection")); + } + + @Override + public EnumAction getItemUseAction(ItemStack p_77661_1_) { + return EnumAction.drink; + } + + @Override + public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) { + if (p_77659_1_.stackTagCompound == null || !p_77659_1_.stackTagCompound.hasKey("TeaOwner")) return p_77659_1_; + if (!p_77659_1_ + .stackTagCompound + .getString("TeaOwner") + .equals(p_77659_3_.getUniqueID().toString())) return p_77659_1_; + p_77659_3_.setItemInUse(p_77659_1_, 32); + return p_77659_1_; + } + + @Override + public ItemStack onEaten(ItemStack stack, World p_77654_2_, EntityPlayer p_77654_3_) { + if (p_77654_2_.isRemote) return stack; + if (!(p_77654_3_ instanceof EntityPlayerMP)) return stack; + if (stack.stackTagCompound == null || !stack.stackTagCompound.hasKey("TeaOwner")) return stack; + if (!stack.stackTagCompound + .getString("TeaOwner") + .equals(p_77654_3_.getUniqueID().toString())) return stack; + p_77654_3_.addChatComponentMessage(new ChatComponentText( + EnumChatFormatting.GREEN + StatCollector.translateToLocal("item.teacollection.mmm"))); + p_77654_3_.triggerAchievement(achievement); + return stack; + } + + @Override + public int getMaxItemUseDuration() { + return 32; + } + + @Override + public String getDisplayName(ItemStack stack) { + if (!ModUtils.isClientSided) return super.getDisplayName(stack); + if (stack.stackTagCompound == null + || (!stack.stackTagCompound.hasKey("TeaOwner") + || stack.stackTagCompound + .getString("TeaOwner") + .equals(Minecraft.getMinecraft() + .thePlayer + .getUniqueID() + .toString()))) return super.getDisplayName(stack); + return EnumChatFormatting.GOLD + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + "???????"; + } + + @Override + public void onUpdate( + ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, boolean p_77663_5_) { + if (p_77663_2_.isRemote) return; + if (!(p_77663_3_ instanceof EntityPlayerMP)) return; + NBTTagCompound tag = p_77663_1_.stackTagCompound; + if (tag == null) tag = p_77663_1_.stackTagCompound = new NBTTagCompound(); + if (tag.hasKey("display")) tag.removeTag("display"); + if (tag.hasKey("TeaOwner")) return; + tag.setString("TeaOwner", p_77663_3_.getPersistentID().toString()); + } + + private static class TeaPage extends AchievementPage { + + public TeaPage() { + super("Tea"); + } + + LinkedList<Achievement> unlockedAchievements = new LinkedList<>(); + + @Override + public List<Achievement> getAchievements() { + if (!ModUtils.isClientSided) return super.getAchievements(); + + if (new Throwable().getStackTrace()[1].getMethodName().equals("isAchievementInPages")) + return super.getAchievements(); // 5HEAD FIX + + EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; + unlockedAchievements.clear(); + for (Achievement achievement : achievements) + if (player.getStatFileWriter().hasAchievementUnlocked(achievement)) + unlockedAchievements.add(achievement); + return unlockedAchievements; + } + + private LinkedList<Achievement> getAchievementsOriginal() { + return (LinkedList<Achievement>) super.getAchievements(); + } + } +} diff --git a/src/main/java/kubatech/loaders/item/items/TeaUltimate.java b/src/main/java/kubatech/loaders/item/items/TeaUltimate.java new file mode 100644 index 0000000000..879d3117ad --- /dev/null +++ b/src/main/java/kubatech/loaders/item/items/TeaUltimate.java @@ -0,0 +1,67 @@ +/* + * KubaTech - Gregtech Addon + * Copyright (C) 2022 kuba6000 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <https://www.gnu.org/licenses/>. + * + */ + +package kubatech.loaders.item.items; + +import java.util.Random; +import kubatech.api.utils.FastRandom; +import kubatech.api.utils.ModUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +public class TeaUltimate extends Tea { + public TeaUltimate() { + super("ultimate_tea"); + } + + private static final String[] Colors = new String[] { + "\u00a70", "\u00a71", "\u00a72", "\u00a73", "\u00a74", "\u00a75", "\u00a76", "\u00a77", "\u00a78", "\u00a79", + "\u00a7a", "\u00a7b", "\u00a7c", "\u00a7d", "\u00a7e", "\u00a7f", + }; + private static final Random rnd = new FastRandom(); + private static String name = ""; + private static long timeCounter = 0; + + private static String rndColor() { + return Colors[rnd.nextInt(Colors.length)] + EnumChatFormatting.BOLD + "" + EnumChatFormatting.OBFUSCATED; + } + + @Override + public String getDisplayName(ItemStack stack) { + if (!ModUtils.isClientSided) return super.getDisplayName(stack); + if (stack.stackTagCompound == null + || (!stack.stackTagCompound.hasKey("TeaOwner") + || stack.stackTagCompound + .getString("TeaOwner") + .equals(Minecraft.getMinecraft() + .thePlayer + .getUniqueID() + .toString()))) { + long current = System.currentTimeMillis(); + if (current - timeCounter > 200) { + timeCounter = current; + name = rndColor() + "U" + rndColor() + "L" + rndColor() + "T" + rndColor() + "I" + rndColor() + "M" + + rndColor() + "A" + rndColor() + "T" + rndColor() + "E"; + } + return String.format(super.getDisplayName(stack), name + EnumChatFormatting.RESET); + } + return EnumChatFormatting.GOLD + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + "???????"; + } +} |