diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2023-04-10 21:02:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 21:02:49 +0200 |
commit | 0ecb697d75b25206daf921ecec1c910d6ab77491 (patch) | |
tree | 1200eb0151e16c9b21187a0f764dced1d9fd9e91 /src/main/java/kubatech/loaders | |
parent | e0c9332c12847e4705ea29aa0ed15dcb3806dca4 (diff) | |
download | GT5-Unofficial-0ecb697d75b25206daf921ecec1c910d6ab77491.tar.gz GT5-Unofficial-0ecb697d75b25206daf921ecec1c910d6ab77491.tar.bz2 GT5-Unofficial-0ecb697d75b25206daf921ecec1c910d6ab77491.zip |
Tea Network update: still alpha (#69)
* Move to UUID checking and BigInteger tea count
* Research category
* Start working on tea limit
* Maybe
* Update en_US.lang
* Fix
* Save UUID mapping
* Mark dirty
* Fixes
Diffstat (limited to 'src/main/java/kubatech/loaders')
10 files changed, 165 insertions, 50 deletions
diff --git a/src/main/java/kubatech/loaders/BlockLoader.java b/src/main/java/kubatech/loaders/BlockLoader.java index feed715fa7..b16fd55b4e 100644 --- a/src/main/java/kubatech/loaders/BlockLoader.java +++ b/src/main/java/kubatech/loaders/BlockLoader.java @@ -14,7 +14,9 @@ import kubatech.api.enums.ItemList; import kubatech.loaders.block.KubaBlock; import kubatech.loaders.block.KubaItemBlock; import kubatech.loaders.block.blocks.TeaAcceptor; +import kubatech.loaders.block.blocks.TeaStorage; import kubatech.tileentity.TeaAcceptorTile; +import kubatech.tileentity.TeaStorageTile; import net.minecraft.block.material.Material; import net.minecraft.item.ItemBlock; @@ -28,9 +30,11 @@ public class BlockLoader { public static void registerBlocks() { GameRegistry.registerTileEntity(TeaAcceptorTile.class, "KT_TeaAcceptor"); + GameRegistry.registerTileEntity(TeaStorageTile.class, "KT_TeaStorage"); GameRegistry.registerBlock(kubaBlock, null, "kubablocks"); GameRegistry.registerItem(kubaItemBlock, "kubablocks"); ItemList.TeaAcceptor.set(kubaBlock.registerProxyBlock(new TeaAcceptor())); + ItemList.TeaStorage.set(kubaBlock.registerProxyBlock(new TeaStorage())); } } diff --git a/src/main/java/kubatech/loaders/MTLoader.java b/src/main/java/kubatech/loaders/MTLoader.java index d223e83951..b39c99e795 100644 --- a/src/main/java/kubatech/loaders/MTLoader.java +++ b/src/main/java/kubatech/loaders/MTLoader.java @@ -11,7 +11,6 @@ package kubatech.loaders; import kubatech.Tags; -import kubatech.api.LoaderReference; import minetweaker.MineTweakerImplementationAPI; import org.apache.logging.log4j.LogManager; @@ -31,6 +30,5 @@ public class MTLoader { public void MTOnPostReload(MineTweakerImplementationAPI.ReloadEvent reloadEvent) { LOG.info("MT Recipes Loaded!"); - if (LoaderReference.Thaumcraft) TCLoader.register(); } } diff --git a/src/main/java/kubatech/loaders/TCLoader.java b/src/main/java/kubatech/loaders/TCLoader.java index a4141d4ba5..37aed521cc 100644 --- a/src/main/java/kubatech/loaders/TCLoader.java +++ b/src/main/java/kubatech/loaders/TCLoader.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.stream.Collectors; +import kubatech.Tags; import kubatech.api.LoaderReference; import kubatech.api.enums.ItemList; import kubatech.api.utils.ItemID; @@ -22,6 +23,7 @@ import kubatech.loaders.item.items.TeaUltimate; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import thaumcraft.api.ThaumcraftApi; @@ -36,9 +38,13 @@ import cpw.mods.fml.common.registry.GameRegistry; public class TCLoader { - public static void load() {} + public static final String TCCategoryKey = "KUBATECH"; - public static void register() { + public static void init() { + ResearchCategories.registerCategory( + TCCategoryKey, + new ResourceLocation(Tags.MODID, "textures/gui/green_tea.png"), + new ResourceLocation("thaumcraft", "textures/gui/gui_researchback.png")); if (!LoaderReference.GTNHCoreMod || !LoaderReference.DraconicEvolution) return; registerRecipe(); registerResearch(); @@ -102,7 +108,7 @@ public class TCLoader { if (ultimateTeaResearch == null) { ultimateTeaResearch = new ResearchItem( "KT_UltimateTea", - "NEWHORIZONS", + TCCategoryKey, new AspectList().add(Aspect.MAGIC, 1).add(Aspect.HEAL, 1).add(Aspect.PLANT, 1) .add(Aspect.EXCHANGE, 1), -2, diff --git a/src/main/java/kubatech/loaders/block/BlockProxy.java b/src/main/java/kubatech/loaders/block/BlockProxy.java index 4ce6aa820d..a546aa80d8 100644 --- a/src/main/java/kubatech/loaders/block/BlockProxy.java +++ b/src/main/java/kubatech/loaders/block/BlockProxy.java @@ -31,12 +31,20 @@ import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; public class BlockProxy { private final String unlocalizedName; - private final String texturepath; - private IIcon icon; + private final String sideTexturePath; + private final String topBottomTexturePath; + private IIcon sideIcon; + private IIcon topBottomIcon; public BlockProxy(String unlocalizedName, String texture) { this.unlocalizedName = "kubablock." + unlocalizedName; - texturepath = Tags.MODID + ":" + texture; + sideTexturePath = topBottomTexturePath = Tags.MODID + ":" + texture; + } + + public BlockProxy(String unlocalizedName, String sideTexture, String topBottomTexture) { + this.unlocalizedName = "kubablock." + unlocalizedName; + sideTexturePath = Tags.MODID + ":" + sideTexture; + topBottomTexturePath = Tags.MODID + ":" + topBottomTexture; } public void itemInit(int ID) {} @@ -58,11 +66,14 @@ public class BlockProxy { public void onBlockPlaced(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {} public void registerIcon(IIconRegister iconRegister) { - icon = iconRegister.registerIcon(texturepath); + sideIcon = iconRegister.registerIcon(sideTexturePath); + if (sideTexturePath.equals(topBottomTexturePath)) topBottomIcon = sideIcon; + else topBottomIcon = iconRegister.registerIcon(topBottomTexturePath); } public IIcon getIcon(int side) { - return icon; + if (side <= 1) return topBottomIcon; + else return sideIcon; } public String getUnlocalizedName() { diff --git a/src/main/java/kubatech/loaders/block/KubaBlock.java b/src/main/java/kubatech/loaders/block/KubaBlock.java index 92481c3f8a..52b378dbf5 100644 --- a/src/main/java/kubatech/loaders/block/KubaBlock.java +++ b/src/main/java/kubatech/loaders/block/KubaBlock.java @@ -107,6 +107,11 @@ public class KubaBlock extends Block { } @Override + public int damageDropped(int meta) { + return meta; + } + + @Override public void registerBlockIcons(IIconRegister p_149651_1_) { blocks.values().forEach(b -> b.registerIcon(p_149651_1_)); } diff --git a/src/main/java/kubatech/loaders/block/KubaItemBlock.java b/src/main/java/kubatech/loaders/block/KubaItemBlock.java index 8d497a6a0f..bdd0c6eecd 100644 --- a/src/main/java/kubatech/loaders/block/KubaItemBlock.java +++ b/src/main/java/kubatech/loaders/block/KubaItemBlock.java @@ -17,6 +17,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class KubaItemBlock extends ItemBlock { @@ -26,6 +27,12 @@ public class KubaItemBlock extends ItemBlock { } @Override + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, + float hitX, float hitY, float hitZ, int metadata) { + return super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata); + } + + @Override public void registerIcons(IIconRegister p_94581_1_) { super.registerIcons(p_94581_1_); } @@ -45,4 +52,9 @@ public class KubaItemBlock extends ItemBlock { public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { KubaBlock.blocks.get(p_77624_1_.getItemDamage()).addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); } + + @Override + public int getMetadata(int p_77647_1_) { + return p_77647_1_; + } } diff --git a/src/main/java/kubatech/loaders/block/blocks/TeaAcceptor.java b/src/main/java/kubatech/loaders/block/blocks/TeaAcceptor.java index 2f4f36db53..9eba767376 100644 --- a/src/main/java/kubatech/loaders/block/blocks/TeaAcceptor.java +++ b/src/main/java/kubatech/loaders/block/blocks/TeaAcceptor.java @@ -26,7 +26,7 @@ import net.minecraft.world.World; public class TeaAcceptor extends BlockProxy implements IProxyTileEntityProvider { public TeaAcceptor() { - super("tea_acceptor", "tea_acceptor"); + super("tea_acceptor", "tea_acceptor", "blank"); } @Override @@ -38,7 +38,7 @@ public class TeaAcceptor extends BlockProxy implements IProxyTileEntityProvider public void onBlockPlaced(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { if (world.isRemote) return; if (!(player instanceof EntityPlayerMP)) return; - ((TeaAcceptorTile) world.getTileEntity(x, y, z)).setTeaOwner(player.getCommandSenderName()); + ((TeaAcceptorTile) world.getTileEntity(x, y, z)).setTeaOwner(player.getPersistentID()); } @Override diff --git a/src/main/java/kubatech/loaders/block/blocks/TeaStorage.java b/src/main/java/kubatech/loaders/block/blocks/TeaStorage.java new file mode 100644 index 0000000000..a80b73fce0 --- /dev/null +++ b/src/main/java/kubatech/loaders/block/blocks/TeaStorage.java @@ -0,0 +1,46 @@ +package kubatech.loaders.block.blocks; + +import static kubatech.api.Variables.numberFormat; + +import java.util.List; + +import kubatech.loaders.block.BlockProxy; +import kubatech.loaders.block.IProxyTileEntityProvider; +import kubatech.tileentity.TeaStorageTile; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +public class TeaStorage extends BlockProxy implements IProxyTileEntityProvider { + + public TeaStorage() { + super("tea_storage", "tea_storage"); + } + + @Override + public TileEntity createTileEntity(World world) { + return new TeaStorageTile(); + } + + @Override + public void onBlockPlaced(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { + if (world.isRemote) return; + if (!(player instanceof EntityPlayerMP)) return; + ((TeaStorageTile) world.getTileEntity(x, y, z)).setTeaOwner(player.getPersistentID()); + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer entity, List<String> tooltipList, boolean showDebugInfo) { + tooltipList.add("Extends Tea Storage by " + EnumChatFormatting.RED + numberFormat.format(Long.MAX_VALUE)); + } + + @Override + public float getResistance() { + return 999999999999.f; + } +} diff --git a/src/main/java/kubatech/loaders/item/items/TeaCollection.java b/src/main/java/kubatech/loaders/item/items/TeaCollection.java index 5ef3995301..46c13a0032 100644 --- a/src/main/java/kubatech/loaders/item/items/TeaCollection.java +++ b/src/main/java/kubatech/loaders/item/items/TeaCollection.java @@ -12,13 +12,13 @@ package kubatech.loaders.item.items; import java.util.LinkedList; import java.util.List; +import java.util.UUID; 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; @@ -48,19 +48,29 @@ public class TeaCollection extends ItemProxy { 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, String username) { + 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(username); + return stack.stackTagCompound.getString("TeaOwner").equals(player); } - private boolean checkOrSetTeaOwner(ItemStack stack, String username) { + private boolean checkOrSetTeaOwner(ItemStack stack, EntityPlayer player) { NBTTagCompound tag = stack.stackTagCompound; - if (tag == null || !stack.stackTagCompound.hasKey("TeaOwner")) { - stack.setTagInfo("TeaOwner", new NBTTagString(username)); + if (tag == null || !stack.stackTagCompound.hasKey("TeaOwnerUUID")) { + stack.setTagInfo("TeaOwnerUUID", new NBTTagString(player.getPersistentID().toString())); + stack.setTagInfo("TeaOwner", new NBTTagString(player.getCommandSenderName())); return true; } - return stack.stackTagCompound.getString("TeaOwner").equals(username); + if (stack.stackTagCompound.getString("TeaOwnerUUID").equals(player.getPersistentID().toString())) { + stack.setTagInfo("TeaOwner", new NBTTagString(player.getCommandSenderName())); + return true; + } else return false; } @Override @@ -136,6 +146,7 @@ public class TeaCollection extends ItemProxy { 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); } @@ -146,7 +157,7 @@ public class TeaCollection extends ItemProxy { public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isCurrentItem) { if (world.isRemote) return; if (!(entity instanceof EntityPlayerMP)) return; - checkOrSetTeaOwner(stack, entity.getCommandSenderName()); + checkOrSetTeaOwner(stack, (EntityPlayer) entity); NBTTagCompound tag = stack.stackTagCompound; if (tag.hasKey("display")) tag.removeTag("display"); } @@ -166,10 +177,9 @@ public class TeaCollection extends ItemProxy { 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)) + if (Minecraft.getMinecraft().thePlayer.getStatFileWriter().hasAchievementUnlocked(achievement)) unlockedAchievements.add(achievement); return unlockedAchievements; } diff --git a/src/main/java/kubatech/loaders/item/items/TeaUltimate.java b/src/main/java/kubatech/loaders/item/items/TeaUltimate.java index 35b4ae28f1..ec7da06b2d 100644 --- a/src/main/java/kubatech/loaders/item/items/TeaUltimate.java +++ b/src/main/java/kubatech/loaders/item/items/TeaUltimate.java @@ -10,14 +10,18 @@ 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 kubatech.api.enums.ItemList; +import kubatech.api.tea.TeaNetwork; import kubatech.api.utils.ModUtils; import kubatech.api.utils.StringUtils; import kubatech.loaders.item.IItemProxyGUI; -import kubatech.savedata.PlayerData; -import kubatech.savedata.PlayerDataManager; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; @@ -26,11 +30,11 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; +import codechicken.nei.NEIClientUtils; + import com.gtnewhorizons.modularui.api.ModularUITextures; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; @@ -64,7 +68,7 @@ public class TeaUltimate extends TeaCollection implements IItemProxyGUI { @Override public String getDisplayName(ItemStack stack) { - if (!ModUtils.isClientSided) return super.getDisplayName(stack); + if (!ModUtils.isClientSided || Minecraft.getMinecraft().thePlayer == null) return super.getDisplayName(stack); if (checkTeaOwner(stack, Minecraft.getMinecraft().thePlayer.getCommandSenderName())) { return getUltimateTeaDisplayName(super.getDisplayName(stack)); } @@ -75,10 +79,12 @@ public class TeaUltimate extends TeaCollection implements IItemProxyGUI { public ModularWindow createWindow(ItemStack stack, EntityPlayer player) { ModularWindow.Builder builder = ModularWindow.builder(200, 150); builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); - final PlayerData playerData = PlayerDataManager.getPlayer(player.getCommandSenderName()); + 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<BigInteger> teaAmount = new AtomicReference<>(BigInteger.ZERO); + AtomicReference<BigInteger> teaLimit = new AtomicReference<>(BigInteger.ZERO); builder.widget( new TabContainer() .setButtonSize( @@ -127,11 +133,33 @@ public class TeaUltimate extends TeaCollection implements IItemProxyGUI { .addChild( new DynamicTextWidget( () -> new Text( - "Tea: " + (playerData == null ? "ERROR" - : NumberFormat.getInstance() - .format(playerData.teaAmount))) - .color(Color.GREEN.normal)) - .setPos(20, 20))) + "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( @@ -143,10 +171,7 @@ public class TeaUltimate extends TeaCollection implements IItemProxyGUI { new ButtonWidget() .setOnClick((Widget.ClickData clickData, Widget widget) -> { if (!(player instanceof EntityPlayerMP)) return; - if (playerData == null || playerData.teaAmount < 50_000L) - return; - playerData.teaAmount -= 50_000L; - playerData.markDirty(); + if (!teaNetwork.canAfford(50_000, true)) return; if (player.inventory.addItemStackToInventory( ItemList.TeaAcceptorResearchNote.get(1))) return; @@ -187,7 +212,7 @@ public class TeaUltimate extends TeaCollection implements IItemProxyGUI { public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entity) { if (world.isRemote) return stack; if (!(entity instanceof EntityPlayerMP)) return stack; - if (!checkTeaOwner(stack, entity.getCommandSenderName())) return stack; + if (!checkTeaOwner(stack, entity.getPersistentID())) return stack; openHeldItemGUI(entity); return stack; } @@ -197,18 +222,16 @@ public class TeaUltimate extends TeaCollection implements IItemProxyGUI { if (world.isRemote) return; if (!(entity instanceof EntityPlayerMP)) return; super.onUpdate(stack, world, entity, slot, isCurrentItem); - if (checkTeaOwner(stack, entity.getCommandSenderName())) { - PlayerData playerData = PlayerDataManager.getPlayer(entity.getCommandSenderName()); - if (playerData == null) return; - playerData.teaAmount++; - playerData.markDirty(); - - 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; - } - } + 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; } } + */ } } } |