From 1b820de08a05070909a267e17f033fcf58ac8710 Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Mon, 2 Sep 2024 23:17:17 +0200 Subject: 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 --- .../java/kubatech/loaders/item/items/ItemTea.java | 72 +++++++ .../loaders/item/items/ItemTeaCollection.java | 209 ++++++++++++++++++++ .../loaders/item/items/ItemTeaIngredient.java | 41 ++++ .../loaders/item/items/ItemTeaUltimate.java | 216 +++++++++++++++++++++ src/main/java/kubatech/loaders/item/items/Tea.java | 72 ------- .../kubatech/loaders/item/items/TeaCollection.java | 209 -------------------- .../kubatech/loaders/item/items/TeaIngredient.java | 41 ---- .../kubatech/loaders/item/items/TeaUltimate.java | 216 --------------------- 8 files changed, 538 insertions(+), 538 deletions(-) create mode 100644 src/main/java/kubatech/loaders/item/items/ItemTea.java create mode 100644 src/main/java/kubatech/loaders/item/items/ItemTeaCollection.java create mode 100644 src/main/java/kubatech/loaders/item/items/ItemTeaIngredient.java create mode 100644 src/main/java/kubatech/loaders/item/items/ItemTeaUltimate.java delete mode 100644 src/main/java/kubatech/loaders/item/items/Tea.java delete mode 100644 src/main/java/kubatech/loaders/item/items/TeaCollection.java delete mode 100644 src/main/java/kubatech/loaders/item/items/TeaIngredient.java delete mode 100644 src/main/java/kubatech/loaders/item/items/TeaUltimate.java (limited to 'src/main/java/kubatech/loaders/item') diff --git a/src/main/java/kubatech/loaders/item/items/ItemTea.java b/src/main/java/kubatech/loaders/item/items/ItemTea.java new file mode 100644 index 0000000000..5beb813053 --- /dev/null +++ b/src/main/java/kubatech/loaders/item/items/ItemTea.java @@ -0,0 +1,72 @@ +/* + * 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 . + * spotless:on + */ + +package kubatech.loaders.item.items; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import kubatech.loaders.item.ItemProxy; + +public class ItemTea extends ItemProxy { + + private final int heal; + private final float saturation; + + public ItemTea(String unlocalizedName, int heal, float saturation) { + super("tea." + unlocalizedName, "tea/" + unlocalizedName); + this.heal = heal; + this.saturation = saturation; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer entity, List tooltipList, boolean showDebugInfo) { + tooltipList.add("Tea"); + } + + @Override + public EnumAction getItemUseAction(ItemStack stack) { + return EnumAction.drink; + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entity) { + entity.setItemInUse(stack, getMaxItemUseDuration()); + return stack; + } + + @Override + public ItemStack onEaten(ItemStack stack, World world, EntityPlayer entity) { + if (!entity.capabilities.isCreativeMode) --stack.stackSize; + entity.getFoodStats() + .addStats(heal, saturation); + world.playSoundAtEntity(entity, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); + return stack; + } + + @Override + public int getMaxItemUseDuration() { + return 32; + } +} 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 . + * 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 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 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 unlockedAchievements = new LinkedList<>(); + + @Override + public List 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 getAchievementsOriginal() { + return (LinkedList) super.getAchievements(); + } + } +} diff --git a/src/main/java/kubatech/loaders/item/items/ItemTeaIngredient.java b/src/main/java/kubatech/loaders/item/items/ItemTeaIngredient.java new file mode 100644 index 0000000000..08dc460d30 --- /dev/null +++ b/src/main/java/kubatech/loaders/item/items/ItemTeaIngredient.java @@ -0,0 +1,41 @@ +/* + * 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 . + * spotless:on + */ + +package kubatech.loaders.item.items; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import kubatech.loaders.item.ItemProxy; + +public class ItemTeaIngredient extends ItemProxy { + + public ItemTeaIngredient(String unlocalizedName) { + super("teaingredient." + unlocalizedName, "teaingredient/" + unlocalizedName); + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer entity, List tooltipList, boolean showDebugInfo) { + tooltipList.add(EnumChatFormatting.GRAY + "This is Tea ingredient"); + } +} diff --git a/src/main/java/kubatech/loaders/item/items/ItemTeaUltimate.java b/src/main/java/kubatech/loaders/item/items/ItemTeaUltimate.java new file mode 100644 index 0000000000..d6df893cd6 --- /dev/null +++ b/src/main/java/kubatech/loaders/item/items/ItemTeaUltimate.java @@ -0,0 +1,216 @@ +/* + * 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 . + * spotless:on + */ + +package kubatech.loaders.item.items; + +import static kubatech.api.Variables.numberFormat; +import static kubatech.api.Variables.numberFormatScientific; + +import java.math.BigInteger; +import java.text.NumberFormat; +import java.util.concurrent.atomic.AtomicReference; + +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.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DynamicTextWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import com.gtnewhorizons.modularui.common.widget.TabButton; +import com.gtnewhorizons.modularui.common.widget.TabContainer; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import codechicken.nei.NEIClientUtils; +import kubatech.api.enums.ItemList; +import kubatech.api.tea.TeaNetwork; +import kubatech.api.utils.ModUtils; +import kubatech.api.utils.StringUtils; +import kubatech.loaders.item.IItemProxyGUI; + +public class ItemTeaUltimate extends ItemTeaCollection implements IItemProxyGUI { + + public ItemTeaUltimate() { + super("ultimate_tea"); + } + + private static String name = ""; + private static long timeCounter = 0; + private static int colorCounter = 0; + + public static String getUltimateTeaDisplayName(String displayName) { + long current = System.currentTimeMillis(); + if (current - timeCounter > 100) { + timeCounter = current; + name = StringUtils.applyRainbow( + "ULTIMATE", + colorCounter++, + EnumChatFormatting.BOLD.toString() + EnumChatFormatting.OBFUSCATED); + } + return String.format(displayName, name + EnumChatFormatting.RESET); + } + + @Override + public String getDisplayName(ItemStack stack) { + if (!ModUtils.isClientSided || Minecraft.getMinecraft().thePlayer == null) return super.getDisplayName(stack); + if (checkTeaOwner(stack, Minecraft.getMinecraft().thePlayer.getCommandSenderName())) { + return getUltimateTeaDisplayName(super.getDisplayName(stack)); + } + return EnumChatFormatting.GOLD + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + "???????"; + } + + @Override + public ModularWindow createWindow(ItemStack stack, EntityPlayer player) { + ModularWindow.Builder builder = ModularWindow.builder(200, 150); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + final TeaNetwork teaNetwork = TeaNetwork.getNetwork(player.getPersistentID()); + IDrawable tab1 = new ItemDrawable(ItemList.LegendaryUltimateTea.get(1)).withFixedSize(18, 18, 4, 6); + IDrawable tab2 = new ItemDrawable(new ItemStack(Blocks.crafting_table)).withFixedSize(18, 18, 4, 6); + IDrawable tab3 = new ItemDrawable(new ItemStack(Items.golden_apple)).withFixedSize(18, 18, 4, 6); + AtomicReference teaAmount = new AtomicReference<>(BigInteger.ZERO); + AtomicReference teaLimit = new AtomicReference<>(BigInteger.ZERO); + builder.widget( + new TabContainer().setButtonSize(28, 32) + .addTabButton( + new TabButton(0) + .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0, 1f, 0.5f), tab1) + .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0.5f, 1f, 1f), tab1) + .setPos(0, -28)) + .addTabButton( + new TabButton(1) + .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), tab2) + .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), tab2) + .setPos(28, -28)) + .addTabButton( + new TabButton(2) + .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), tab3) + .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), tab3) + .setPos(56, -28)) + .addPage( + new MultiChildWidget().addChild( + new TextWidget( + new Text("STATUS").format(EnumChatFormatting.BOLD) + .format(EnumChatFormatting.GOLD) + .shadow()).setPos(10, 5)) + .addChild( + new DynamicTextWidget( + () -> new Text( + "Tea: " + (NEIClientUtils.shiftKey() ? numberFormat.format(teaAmount.get()) + : numberFormatScientific.format(teaAmount.get()))).color(Color.GREEN.dark(3))) + .setSynced(false) + .setPos(20, 20) + .attachSyncer( + new FakeSyncWidget.BigIntegerSyncer( + () -> teaNetwork.teaAmount, + teaAmount::set), + builder)) + .addChild( + new DynamicTextWidget( + () -> new Text( + "Tea limit: " + (NEIClientUtils.shiftKey() ? numberFormat.format(teaLimit.get()) + : numberFormatScientific.format(teaLimit.get()))).color(Color.GREEN.dark(3))) + .setSynced(false) + .setPos(20, 30) + .attachSyncer( + new FakeSyncWidget.BigIntegerSyncer( + () -> teaNetwork.teaLimit, + teaLimit::set), + builder))) + .addPage( + new MultiChildWidget().addChild( + new TextWidget( + new Text("EXCHANGE").format(EnumChatFormatting.BOLD) + .format(EnumChatFormatting.GOLD) + .shadow()).setPos(10, 5)) + .addChild(new ButtonWidget().setOnClick((Widget.ClickData clickData, Widget widget) -> { + if (!(player instanceof EntityPlayerMP)) return; + if (!teaNetwork.canAfford(50_000, true)) return; + if (player.inventory.addItemStackToInventory(ItemList.TeaAcceptorResearchNote.get(1))) + return; + player.entityDropItem(ItemList.TeaAcceptorResearchNote.get(1), 0.5f); + }) + .setBackground(new ItemDrawable().setItem(ItemList.TeaAcceptorResearchNote.get(1))) + .addTooltip("Tea Acceptor Research Note") + .addTooltip( + new Text( + "Cost: " + NumberFormat.getInstance() + .format(50_000) + " Tea").color(Color.GRAY.normal)) + .setPos(20, 20))) + .addPage( + new MultiChildWidget().addChild( + new TextWidget( + new Text("BENEFITS").format(EnumChatFormatting.BOLD) + .format(EnumChatFormatting.GOLD) + .shadow()).setPos(10, 5)) + /* + * .addChild(new ButtonWidget() .setOnClick((Widget.ClickData clickData, Widget widget) -> { if + * (!(player instanceof EntityPlayerMP)) return; if (playerData == null) return; + * playerData.autoRegen = !playerData.autoRegen; playerData.markDirty(); }) .setBackground(new + * ItemDrawable().setItem(new ItemStack(Items.potionitem, 1, 8193))) + * .addTooltip("Regeneration I") .addTooltip("For 1 minute") .addTooltip(new Text("Cost: " + + * NumberFormat.getInstance().format(75_000) + " Tea") .color(Color.GRAY.normal)) // + * .addTooltip( //Find a way to run that on server, or different approach // new + * Text("Autobuy: " + (playerData == null ? "ERROR" : playerData.autoRegen)) // + * .color(Color.GREY.normal)) .setPos(20, 20)) + */ )); + return builder.build(); + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entity) { + if (world.isRemote) return stack; + if (!(entity instanceof EntityPlayerMP)) return stack; + if (!checkTeaOwner(stack, entity.getPersistentID())) return stack; + openHeldItemGUI(entity); + return stack; + } + + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isCurrentItem) { + if (world.isRemote) return; + if (!(entity instanceof EntityPlayerMP)) return; + super.onUpdate(stack, world, entity, slot, isCurrentItem); + if (checkTeaOwner(stack, entity.getPersistentID())) { + TeaNetwork teaNetwork = TeaNetwork.getNetwork(entity.getPersistentID()); + teaNetwork.addTea(1); + + /* + * if (playerData.autoRegen && playerData.teaAmount > 75_000) { if (((EntityPlayerMP) + * entity).getActivePotionEffect(Potion.regeneration) == null) { ((EntityPlayerMP) + * entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1200, 0, true)); playerData.teaAmount -= + * 75_000; } } + */ + } + } +} diff --git a/src/main/java/kubatech/loaders/item/items/Tea.java b/src/main/java/kubatech/loaders/item/items/Tea.java deleted file mode 100644 index f1b3ae3d0b..0000000000 --- a/src/main/java/kubatech/loaders/item/items/Tea.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 . - * spotless:on - */ - -package kubatech.loaders.item.items; - -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.EnumAction; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import kubatech.loaders.item.ItemProxy; - -public class Tea extends ItemProxy { - - private final int heal; - private final float saturation; - - public Tea(String unlocalizedName, int heal, float saturation) { - super("tea." + unlocalizedName, "tea/" + unlocalizedName); - this.heal = heal; - this.saturation = saturation; - } - - @Override - public void addInformation(ItemStack stack, EntityPlayer entity, List tooltipList, boolean showDebugInfo) { - tooltipList.add("Tea"); - } - - @Override - public EnumAction getItemUseAction(ItemStack stack) { - return EnumAction.drink; - } - - @Override - public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entity) { - entity.setItemInUse(stack, getMaxItemUseDuration()); - return stack; - } - - @Override - public ItemStack onEaten(ItemStack stack, World world, EntityPlayer entity) { - if (!entity.capabilities.isCreativeMode) --stack.stackSize; - entity.getFoodStats() - .addStats(heal, saturation); - world.playSoundAtEntity(entity, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); - return stack; - } - - @Override - public int getMaxItemUseDuration() { - return 32; - } -} diff --git a/src/main/java/kubatech/loaders/item/items/TeaCollection.java b/src/main/java/kubatech/loaders/item/items/TeaCollection.java deleted file mode 100644 index efa390c517..0000000000 --- a/src/main/java/kubatech/loaders/item/items/TeaCollection.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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 . - * 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 TeaCollection extends ItemProxy { - - protected static TeaPage teapage; - protected static LinkedList achievements; - protected Achievement achievement; - private final String achievementname; - - public TeaCollection(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 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 unlockedAchievements = new LinkedList<>(); - - @Override - public List 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 getAchievementsOriginal() { - return (LinkedList) super.getAchievements(); - } - } -} diff --git a/src/main/java/kubatech/loaders/item/items/TeaIngredient.java b/src/main/java/kubatech/loaders/item/items/TeaIngredient.java deleted file mode 100644 index 4ff248ea37..0000000000 --- a/src/main/java/kubatech/loaders/item/items/TeaIngredient.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 . - * spotless:on - */ - -package kubatech.loaders.item.items; - -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; - -import kubatech.loaders.item.ItemProxy; - -public class TeaIngredient extends ItemProxy { - - public TeaIngredient(String unlocalizedName) { - super("teaingredient." + unlocalizedName, "teaingredient/" + unlocalizedName); - } - - @Override - public void addInformation(ItemStack stack, EntityPlayer entity, List tooltipList, boolean showDebugInfo) { - tooltipList.add(EnumChatFormatting.GRAY + "This is Tea ingredient"); - } -} diff --git a/src/main/java/kubatech/loaders/item/items/TeaUltimate.java b/src/main/java/kubatech/loaders/item/items/TeaUltimate.java deleted file mode 100644 index cee7eba132..0000000000 --- a/src/main/java/kubatech/loaders/item/items/TeaUltimate.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * 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 . - * spotless:on - */ - -package kubatech.loaders.item.items; - -import static kubatech.api.Variables.numberFormat; -import static kubatech.api.Variables.numberFormatScientific; - -import java.math.BigInteger; -import java.text.NumberFormat; -import java.util.concurrent.atomic.AtomicReference; - -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.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; - -import com.gtnewhorizons.modularui.api.ModularUITextures; -import com.gtnewhorizons.modularui.api.drawable.IDrawable; -import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; -import com.gtnewhorizons.modularui.api.drawable.Text; -import com.gtnewhorizons.modularui.api.math.Color; -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.widget.Widget; -import com.gtnewhorizons.modularui.common.widget.ButtonWidget; -import com.gtnewhorizons.modularui.common.widget.DynamicTextWidget; -import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; -import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; -import com.gtnewhorizons.modularui.common.widget.TabButton; -import com.gtnewhorizons.modularui.common.widget.TabContainer; -import com.gtnewhorizons.modularui.common.widget.TextWidget; - -import codechicken.nei.NEIClientUtils; -import kubatech.api.enums.ItemList; -import kubatech.api.tea.TeaNetwork; -import kubatech.api.utils.ModUtils; -import kubatech.api.utils.StringUtils; -import kubatech.loaders.item.IItemProxyGUI; - -public class TeaUltimate extends TeaCollection implements IItemProxyGUI { - - public TeaUltimate() { - super("ultimate_tea"); - } - - private static String name = ""; - private static long timeCounter = 0; - private static int colorCounter = 0; - - public static String getUltimateTeaDisplayName(String displayName) { - long current = System.currentTimeMillis(); - if (current - timeCounter > 100) { - timeCounter = current; - name = StringUtils.applyRainbow( - "ULTIMATE", - colorCounter++, - EnumChatFormatting.BOLD.toString() + EnumChatFormatting.OBFUSCATED); - } - return String.format(displayName, name + EnumChatFormatting.RESET); - } - - @Override - public String getDisplayName(ItemStack stack) { - if (!ModUtils.isClientSided || Minecraft.getMinecraft().thePlayer == null) return super.getDisplayName(stack); - if (checkTeaOwner(stack, Minecraft.getMinecraft().thePlayer.getCommandSenderName())) { - return getUltimateTeaDisplayName(super.getDisplayName(stack)); - } - return EnumChatFormatting.GOLD + "" + EnumChatFormatting.BOLD + "" + EnumChatFormatting.ITALIC + "???????"; - } - - @Override - public ModularWindow createWindow(ItemStack stack, EntityPlayer player) { - ModularWindow.Builder builder = ModularWindow.builder(200, 150); - builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); - final TeaNetwork teaNetwork = TeaNetwork.getNetwork(player.getPersistentID()); - IDrawable tab1 = new ItemDrawable(ItemList.LegendaryUltimateTea.get(1)).withFixedSize(18, 18, 4, 6); - IDrawable tab2 = new ItemDrawable(new ItemStack(Blocks.crafting_table)).withFixedSize(18, 18, 4, 6); - IDrawable tab3 = new ItemDrawable(new ItemStack(Items.golden_apple)).withFixedSize(18, 18, 4, 6); - AtomicReference teaAmount = new AtomicReference<>(BigInteger.ZERO); - AtomicReference teaLimit = new AtomicReference<>(BigInteger.ZERO); - builder.widget( - new TabContainer().setButtonSize(28, 32) - .addTabButton( - new TabButton(0) - .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0, 1f, 0.5f), tab1) - .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0.5f, 1f, 1f), tab1) - .setPos(0, -28)) - .addTabButton( - new TabButton(1) - .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), tab2) - .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), tab2) - .setPos(28, -28)) - .addTabButton( - new TabButton(2) - .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), tab3) - .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), tab3) - .setPos(56, -28)) - .addPage( - new MultiChildWidget().addChild( - new TextWidget( - new Text("STATUS").format(EnumChatFormatting.BOLD) - .format(EnumChatFormatting.GOLD) - .shadow()).setPos(10, 5)) - .addChild( - new DynamicTextWidget( - () -> new Text( - "Tea: " + (NEIClientUtils.shiftKey() ? numberFormat.format(teaAmount.get()) - : numberFormatScientific.format(teaAmount.get()))).color(Color.GREEN.dark(3))) - .setSynced(false) - .setPos(20, 20) - .attachSyncer( - new FakeSyncWidget.BigIntegerSyncer( - () -> teaNetwork.teaAmount, - teaAmount::set), - builder)) - .addChild( - new DynamicTextWidget( - () -> new Text( - "Tea limit: " + (NEIClientUtils.shiftKey() ? numberFormat.format(teaLimit.get()) - : numberFormatScientific.format(teaLimit.get()))).color(Color.GREEN.dark(3))) - .setSynced(false) - .setPos(20, 30) - .attachSyncer( - new FakeSyncWidget.BigIntegerSyncer( - () -> teaNetwork.teaLimit, - teaLimit::set), - builder))) - .addPage( - new MultiChildWidget().addChild( - new TextWidget( - new Text("EXCHANGE").format(EnumChatFormatting.BOLD) - .format(EnumChatFormatting.GOLD) - .shadow()).setPos(10, 5)) - .addChild(new ButtonWidget().setOnClick((Widget.ClickData clickData, Widget widget) -> { - if (!(player instanceof EntityPlayerMP)) return; - if (!teaNetwork.canAfford(50_000, true)) return; - if (player.inventory.addItemStackToInventory(ItemList.TeaAcceptorResearchNote.get(1))) - return; - player.entityDropItem(ItemList.TeaAcceptorResearchNote.get(1), 0.5f); - }) - .setBackground(new ItemDrawable().setItem(ItemList.TeaAcceptorResearchNote.get(1))) - .addTooltip("Tea Acceptor Research Note") - .addTooltip( - new Text( - "Cost: " + NumberFormat.getInstance() - .format(50_000) + " Tea").color(Color.GRAY.normal)) - .setPos(20, 20))) - .addPage( - new MultiChildWidget().addChild( - new TextWidget( - new Text("BENEFITS").format(EnumChatFormatting.BOLD) - .format(EnumChatFormatting.GOLD) - .shadow()).setPos(10, 5)) - /* - * .addChild(new ButtonWidget() .setOnClick((Widget.ClickData clickData, Widget widget) -> { if - * (!(player instanceof EntityPlayerMP)) return; if (playerData == null) return; - * playerData.autoRegen = !playerData.autoRegen; playerData.markDirty(); }) .setBackground(new - * ItemDrawable().setItem(new ItemStack(Items.potionitem, 1, 8193))) - * .addTooltip("Regeneration I") .addTooltip("For 1 minute") .addTooltip(new Text("Cost: " + - * NumberFormat.getInstance().format(75_000) + " Tea") .color(Color.GRAY.normal)) // - * .addTooltip( //Find a way to run that on server, or different approach // new - * Text("Autobuy: " + (playerData == null ? "ERROR" : playerData.autoRegen)) // - * .color(Color.GREY.normal)) .setPos(20, 20)) - */ )); - return builder.build(); - } - - @Override - public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entity) { - if (world.isRemote) return stack; - if (!(entity instanceof EntityPlayerMP)) return stack; - if (!checkTeaOwner(stack, entity.getPersistentID())) return stack; - openHeldItemGUI(entity); - return stack; - } - - @Override - public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isCurrentItem) { - if (world.isRemote) return; - if (!(entity instanceof EntityPlayerMP)) return; - super.onUpdate(stack, world, entity, slot, isCurrentItem); - if (checkTeaOwner(stack, entity.getPersistentID())) { - TeaNetwork teaNetwork = TeaNetwork.getNetwork(entity.getPersistentID()); - teaNetwork.addTea(1); - - /* - * if (playerData.autoRegen && playerData.teaAmount > 75_000) { if (((EntityPlayerMP) - * entity).getActivePotionEffect(Potion.regeneration) == null) { ((EntityPlayerMP) - * entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1200, 0, true)); playerData.teaAmount -= - * 75_000; } } - */ - } - } -} -- cgit