aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java
diff options
context:
space:
mode:
authorNotAPenguin <michiel.vandeginste@gmail.com>2024-09-02 23:17:17 +0200
committerGitHub <noreply@github.com>2024-09-02 23:17:17 +0200
commit1b820de08a05070909a267e17f033fcf58ac8710 (patch)
tree02831a025986a06b20f87e5bcc69d1e0c639a342 /src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java
parentafd3fd92b6a6ab9ab0d0dc3214e6bc8ff7a86c9b (diff)
downloadGT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.gz
GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.bz2
GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.zip
The Great Renaming (#3014)
* move kekztech to a single root dir * move detrav to a single root dir * move gtnh-lanthanides to a single root dir * move tectech and delete some gross reflection in gt++ * remove more reflection inside gt5u * delete more reflection in gt++ * fix imports * move bartworks and bwcrossmod * fix proxies * move galactigreg and ggfab * move gtneioreplugin * try to fix gt++ bee loader * apply the rename rules to BW * apply rename rules to bwcrossmod * apply rename rules to detrav scanner mod * apply rename rules to galacticgreg * apply rename rules to ggfab * apply rename rules to goodgenerator * apply rename rules to gtnh-lanthanides * apply rename rules to gt++ * apply rename rules to kekztech * apply rename rules to kubatech * apply rename rules to tectech * apply rename rules to gt apply the rename rules to gt * fix tt import * fix mui hopefully * fix coremod except intergalactic * rename assline recipe class * fix a class name i stumbled on * rename StructureUtility to GTStructureUtility to prevent conflict with structurelib * temporary rename of GTTooltipDataCache to old name * fix gt client/server proxy names
Diffstat (limited to 'src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java')
-rw-r--r--src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java209
1 files changed, 209 insertions, 0 deletions
diff --git a/src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java b/src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java
new file mode 100644
index 0000000000..6b18342462
--- /dev/null
+++ b/src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java
@@ -0,0 +1,209 @@
+/*
+ * spotless:off
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 - 2024 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/>.
+ * spotless:on
+ */
+
+package kubatech.loaders.item.items;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+
+import net.minecraft.client.Minecraft;
+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.nbt.NBTTagString;
+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;
+
+import kubatech.api.utils.ModUtils;
+import kubatech.loaders.ItemLoader;
+import kubatech.loaders.item.ItemProxy;
+
+public class ItemTeaCollection extends ItemProxy {
+
+ protected static TeaPage teapage;
+ protected static LinkedList<Achievement> achievements;
+ protected Achievement achievement;
+ private final String achievementname;
+
+ public ItemTeaCollection(String unlocalizedName) {
+ super("teacollection." + unlocalizedName, "tea/" + 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 } };
+
+ boolean checkTeaOwner(ItemStack stack, UUID player) {
+ NBTTagCompound tag = stack.stackTagCompound;
+ if (tag == null || !stack.stackTagCompound.hasKey("TeaOwnerUUID")) return true;
+ return stack.stackTagCompound.getString("TeaOwnerUUID")
+ .equals(player.toString());
+ }
+
+ boolean checkTeaOwner(ItemStack stack, String player) {
+ NBTTagCompound tag = stack.stackTagCompound;
+ if (tag == null || !stack.stackTagCompound.hasKey("TeaOwner")) return true;
+ return stack.stackTagCompound.getString("TeaOwner")
+ .equals(player);
+ }
+
+ private boolean checkOrSetTeaOwner(ItemStack stack, EntityPlayer player) {
+ NBTTagCompound tag = stack.stackTagCompound;
+ if (tag == null || !stack.stackTagCompound.hasKey("TeaOwnerUUID")) {
+ stack.setTagInfo(
+ "TeaOwnerUUID",
+ new NBTTagString(
+ player.getPersistentID()
+ .toString()));
+ stack.setTagInfo("TeaOwner", new NBTTagString(player.getCommandSenderName()));
+ return true;
+ }
+ if (stack.stackTagCompound.getString("TeaOwnerUUID")
+ .equals(
+ player.getPersistentID()
+ .toString())) {
+ stack.setTagInfo("TeaOwner", new NBTTagString(player.getCommandSenderName()));
+ return true;
+ } else return false;
+ }
+
+ @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 stack, EntityPlayer entity, List<String> tooltipList, boolean showDebugInfo) {
+ if (!checkTeaOwner(stack, entity.getCommandSenderName())) {
+ tooltipList.add(
+ EnumChatFormatting.GRAY + ""
+ + EnumChatFormatting.BOLD
+ + ""
+ + EnumChatFormatting.ITALIC
+ + StatCollector.translateToLocal("kubaitem.notyours"));
+ return;
+ }
+ tooltipList.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("kubaitem.fromcollection"));
+ tooltipList.add(
+ EnumChatFormatting.GRAY + ""
+ + EnumChatFormatting.BOLD
+ + ""
+ + EnumChatFormatting.ITALIC
+ + ""
+ + EnumChatFormatting.UNDERLINE
+ + StatCollector.translateToLocal("kubaitem.teacollection"));
+ }
+
+ @Override
+ public EnumAction getItemUseAction(ItemStack stack) {
+ return EnumAction.drink;
+ }
+
+ @Override
+ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entity) {
+ if (!checkTeaOwner(stack, entity.getCommandSenderName())) return stack;
+ entity.setItemInUse(stack, 32);
+ return stack;
+ }
+
+ @Override
+ public ItemStack onEaten(ItemStack stack, World world, EntityPlayer entity) {
+ if (world.isRemote) return stack;
+ if (!(entity instanceof EntityPlayerMP)) return stack;
+ entity.addChatComponentMessage(
+ new ChatComponentText(
+ EnumChatFormatting.GREEN + StatCollector.translateToLocal("kubaitem.teacollection.mmm")));
+ entity.triggerAchievement(achievement);
+ return stack;
+ }
+
+ @Override
+ public int getMaxItemUseDuration() {
+ return 32;
+ }
+
+ @Override
+ public String getDisplayName(ItemStack stack) {
+ if (!ModUtils.isClientSided || Minecraft.getMinecraft().thePlayer == null) {
+ return super.getDisplayName(stack);
+ }
+ // UUID is different on client if in offline mode I think
+ if (checkTeaOwner(stack, Minecraft.getMinecraft().thePlayer.getCommandSenderName())) {
+ return super.getDisplayName(stack);
+ }
+ return EnumChatFormatting.GOLD + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + "???????";
+ }
+
+ @Override
+ public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isCurrentItem) {
+ if (world.isRemote) return;
+ if (!(entity instanceof EntityPlayerMP)) return;
+ checkOrSetTeaOwner(stack, (EntityPlayer) entity);
+ NBTTagCompound tag = stack.stackTagCompound;
+ if (tag.hasKey("display")) tag.removeTag("display");
+ }
+
+ private static class TeaPage extends AchievementPage {
+
+ public TeaPage() {
+ super("Tea");
+ }
+
+ final 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
+
+ unlockedAchievements.clear();
+ for (Achievement achievement : achievements) if (Minecraft.getMinecraft().thePlayer.getStatFileWriter()
+ .hasAchievementUnlocked(achievement)) unlockedAchievements.add(achievement);
+ return unlockedAchievements;
+ }
+
+ private LinkedList<Achievement> getAchievementsOriginal() {
+ return (LinkedList<Achievement>) super.getAchievements();
+ }
+ }
+}