diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2023-12-04 13:04:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-04 13:04:47 +0100 |
commit | 2ee2ff6d97e81340e3209ec46e675ec412112867 (patch) | |
tree | 5e1a6ae3385c701438e573dae60fd750cf68b27a /src/main/java/kubatech/tileentity/gregtech | |
parent | 1ef020a8291957fdd470c76165d279398329e322 (diff) | |
download | GT5-Unofficial-2ee2ff6d97e81340e3209ec46e675ec412112867.tar.gz GT5-Unofficial-2ee2ff6d97e81340e3209ec46e675ec412112867.tar.bz2 GT5-Unofficial-2ee2ff6d97e81340e3209ec46e675ec412112867.zip |
Rework GUIs (#108)
* Update dependencies.gradle
* Move mod id and name to the code
* New EEC gui
* Configuration buttons and tooltip delays
* a
* test
* Move EIG GUI to a new class
* Use the new inventory class in MApiary
* Update DynamicInventory.java
* Fix
* Inventory slots
* Update dependencies.gradle
* test
* MAapiary switchable screen + progress
* Recipe error results + fixes
* Remove commented code
---------
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java/kubatech/tileentity/gregtech')
3 files changed, 431 insertions, 970 deletions
diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeEntityCrusher.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeEntityCrusher.java index b7fec167cb..25b5a43d8f 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeEntityCrusher.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeEntityCrusher.java @@ -24,7 +24,6 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.isAir; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; -import static com.kuba6000.mobsinfo.api.MobRecipe.MobNameToRecipeMap; import static gregtech.api.enums.GT_HatchElement.Energy; import static gregtech.api.enums.GT_HatchElement.InputBus; import static gregtech.api.enums.GT_HatchElement.Maintenance; @@ -34,6 +33,7 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE_GLOW; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_GLOW; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import static gregtech.api.util.GT_StructureUtility.ofFrame; import static kubatech.api.Variables.Author; @@ -61,7 +61,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StatCollector; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; import net.minecraft.world.WorldProviderHell; @@ -82,20 +81,14 @@ import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import com.gtnewhorizons.modularui.api.math.Color; -import com.gtnewhorizons.modularui.api.math.Pos2d; -import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; -import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; -import com.gtnewhorizons.modularui.common.widget.DynamicPositionedRow; -import com.gtnewhorizons.modularui.common.widget.DynamicTextWidget; -import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.SlotWidget; -import com.gtnewhorizons.modularui.common.widget.TextWidget; import com.kuba6000.mobsinfo.api.utils.FastRandom; -import com.kuba6000.mobsinfo.api.utils.ItemID; import com.mojang.authlib.GameProfile; import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry; @@ -121,6 +114,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; @@ -129,6 +123,7 @@ import kubatech.api.LoaderReference; import kubatech.api.helpers.ReflectionHelper; import kubatech.api.implementations.KubaTechGTMultiBlockBase; import kubatech.api.tileentity.CustomTileEntityPacketHandler; +import kubatech.api.utils.ModUtils; import kubatech.client.effect.EntityRenderer; import kubatech.loaders.MobHandlerLoader; import kubatech.network.CustomTileEntityPacket; @@ -223,6 +218,10 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher aNBT.setBoolean("mAnimationEnabled", mAnimationEnabled); aNBT.setByte("mGlassTier", mGlassTier); aNBT.setBoolean("mIsProducingInfernalDrops", mIsProducingInfernalDrops); + if (weaponCache.getStackInSlot(0) != null) aNBT.setTag( + "weaponCache", + weaponCache.getStackInSlot(0) + .writeToNBT(new NBTTagCompound())); } @Override @@ -233,6 +232,8 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher mGlassTier = aNBT.getByte("mGlassTier"); mIsProducingInfernalDrops = !aNBT.hasKey("mIsProducingInfernalDrops") || aNBT.getBoolean("mIsProducingInfernalDrops"); + if (aNBT.hasKey("weaponCache")) + weaponCache.setStackInSlot(0, ItemStack.loadItemStackFromNBT(aNBT.getCompoundTag("weaponCache"))); } @Override @@ -266,7 +267,7 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher .addInfo("Base energy usage: 2,000 EU/t") .addInfo("Supports perfect OC, minimum time: 20 ticks, after that multiplies the outputs.") .addInfo("Recipe time is based on mob health.") - .addInfo("You can additionally put a weapon in the ULV input bus.") + .addInfo("You can additionally put a weapon inside the GUI.") .addInfo("It will speed up the process and apply the looting level from the weapon (maximum 4 levels).") .addInfo(EnumChatFormatting.RED + "Enchanting the spikes inside does nothing!") .addInfo("Also produces 120 Liquid XP per operation.") @@ -287,10 +288,6 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher .addOtherStructurePart("Steel Frame Box", "All vertical edges without corners") .addOtherStructurePart("Diamond spikes", "Inside second layer") .addOutputBus("Any bottom casing", 1) - .addOtherStructurePart( - "1x ULV " + StatCollector.translateToLocal("GT5U.MBTT.InputBus"), - "Any bottom casing", - 1) .addOutputHatch("Any bottom casing", 1) .addEnergyHatch("Any bottom casing", 1) .addMaintenanceHatch("Any bottom casing", 1) @@ -478,12 +475,41 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher private CustomTileEntityPacket mobPacket = null; - private static class WeaponCache { + private static class WeaponCache extends ItemStackHandler { boolean isValid = false; - ItemID id = null; int looting = 0; double attackDamage = 0; + + public WeaponCache() { + super(1); + } + + @Override + protected void onContentsChanged(int slot) { + if (slot != 0) return; + if (ModUtils.isClientThreaded()) return; + ItemStack stack = getStackInSlot(0); + if (stack == null) { + isValid = false; + return; + } + // noinspection unchecked + attackDamage = ((Multimap<String, AttributeModifier>) stack.getAttributeModifiers()) + .get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()) + .stream() + .mapToDouble( + attr -> attr.getAmount() + + (double) EnchantmentHelper.func_152377_a(stack, EnumCreatureAttribute.UNDEFINED)) + .sum(); + looting = Math.min(4, EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, stack)); + isValid = true; + } + + @Override + public boolean isItemValid(int slot, ItemStack stack) { + return Enchantment.looting.canApply(stack); + } } private final WeaponCache weaponCache = new WeaponCache(); @@ -494,14 +520,14 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher public CheckRecipeResult checkProcessing() { if (getBaseMetaTileEntity().isClientSide()) return CheckRecipeResultRegistry.NO_RECIPE; ItemStack aStack = mInventory[1]; - if (aStack == null) return CheckRecipeResultRegistry.NO_RECIPE; + if (aStack == null) return SimpleCheckRecipeResult.ofFailure("EEC_nospawner"); - if (aStack.getItem() != poweredSpawnerItem) return CheckRecipeResultRegistry.NO_RECIPE; + if (aStack.getItem() != poweredSpawnerItem) return SimpleCheckRecipeResult.ofFailure("EEC_nospawner"); - if (aStack.getTagCompound() == null) return CheckRecipeResultRegistry.NO_RECIPE; + if (aStack.getTagCompound() == null) return SimpleCheckRecipeResult.ofFailure("EEC_invalidspawner"); String mobType = aStack.getTagCompound() .getString("mobType"); - if (mobType.isEmpty()) return CheckRecipeResultRegistry.NO_RECIPE; + if (mobType.isEmpty()) return SimpleCheckRecipeResult.ofFailure("EEC_invalidspawner"); if (mobType.equals("Skeleton") && getBaseMetaTileEntity().getWorld().provider instanceof WorldProviderHell && rand.nextInt(5) > 0) mobType = "witherSkeleton"; @@ -510,7 +536,8 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher if (recipe == null) return CheckRecipeResultRegistry.NO_RECIPE; if (!recipe.recipe.isPeacefulAllowed && this.getBaseMetaTileEntity() - .getWorld().difficultySetting == EnumDifficulty.PEACEFUL) return CheckRecipeResultRegistry.NO_RECIPE; + .getWorld().difficultySetting == EnumDifficulty.PEACEFUL) + return SimpleCheckRecipeResult.ofFailure("EEC_peaceful"); if (isInRitualMode && isRitualValid()) { if (getMaxInputEu() < recipe.mEUt / 4) return CheckRecipeResultRegistry.insufficientPower(recipe.mEUt / 4); @@ -524,38 +551,23 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher return CheckRecipeResultRegistry.insufficientPower(recipe.mEUt * 8); double attackDamage = DIAMOND_SPIKES_DAMAGE; // damage from spikes - GT_MetaTileEntity_Hatch_InputBus inputbus = this.mInputBusses.size() == 0 ? null : this.mInputBusses.get(0); - if (inputbus != null && !inputbus.isValid()) inputbus = null; - ItemStack lootingHolder = inputbus == null ? null : inputbus.getStackInSlot(0); weaponCheck: { - // noinspection EqualsBetweenInconvertibleTypes - if (weaponCache.isValid && weaponCache.id.equals(lootingHolder)) break weaponCheck; - if (lootingHolder == null || !Enchantment.looting.canApply(lootingHolder)) { - weaponCache.isValid = false; - break weaponCheck; - } - try { - // noinspection unchecked - weaponCache.attackDamage = ((Multimap<String, AttributeModifier>) lootingHolder - .getAttributeModifiers()) - .get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()) - .stream() - .mapToDouble( - attr -> attr.getAmount() + (double) EnchantmentHelper - .func_152377_a(lootingHolder, EnumCreatureAttribute.UNDEFINED)) - .sum(); - } catch (Exception ex) { - ex.printStackTrace(); + GT_MetaTileEntity_Hatch_InputBus inputbus = this.mInputBusses.size() == 0 ? null + : this.mInputBusses.get(0); + if (inputbus != null && !inputbus.isValid()) inputbus = null; + ItemStack lootingHolder = inputbus == null ? null : inputbus.getStackInSlot(0); + if (lootingHolder == null) break weaponCheck; + if (weaponCache.getStackInSlot(0) != null) break weaponCheck; + if (weaponCache.isItemValid(0, lootingHolder)) { + weaponCache.setStackInSlot(0, lootingHolder); + inputbus.setInventorySlotContents(0, null); + updateSlots(); } - weaponCache.isValid = true; - weaponCache.looting = Math - .min(4, EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, lootingHolder)); - weaponCache.id = ItemID.createNoCopy(lootingHolder, true, true); } if (weaponCache.isValid) attackDamage += weaponCache.attackDamage; if (EECPlayer == null) EECPlayer = new EECFakePlayer(this); - EECPlayer.currentWeapon = lootingHolder; + EECPlayer.currentWeapon = weaponCache.getStackInSlot(0); this.mOutputItems = recipe.generateOutputs( rand, @@ -567,15 +579,16 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher EECPlayer.currentWeapon = null; this.mOutputFluids = new FluidStack[] { FluidRegistry.getFluidStack("xpjuice", 120) }; + ItemStack weapon = weaponCache.getStackInSlot(0); int times = this.calculatePerfectOverclock(this.lEUt, this.mMaxProgresstime); - if (weaponCache.isValid && lootingHolder.isItemStackDamageable()) { - EECPlayer.currentWeapon = lootingHolder; - Item lootingHolderItem = lootingHolder.getItem(); + if (weaponCache.isValid && weapon.isItemStackDamageable()) { + EECPlayer.currentWeapon = weapon; + Item lootingHolderItem = weapon.getItem(); for (int i = 0; i < times + 1; i++) { // noinspection ConstantConditions - if (!lootingHolderItem.hitEntity(lootingHolder, recipe.recipe.entity, EECPlayer)) break; - if (lootingHolder.stackSize == 0) { - inputbus.setInventorySlotContents(0, null); + if (!lootingHolderItem.hitEntity(weapon, recipe.recipe.entity, EECPlayer)) break; + if (weapon.stackSize == 0) { + weaponCache.setStackInSlot(0, null); break; } } @@ -670,77 +683,8 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher } @Override - public boolean useModularUI() { - return true; - } - - @Override - public int getGUIHeight() { - return 166; - } - - @Override - public int getGUIWidth() { - return 176; - } - - @Override - public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.bindPlayerInventory( - buildContext.getPlayer(), - new Pos2d(7, 83), - this.getGUITextureSet() - .getItemSlot()); - } - - @Override - public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.widget( - new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) - .setPos(7, 4) - .setSize(143, 75) - .setEnabled(widget -> !isFixed.apply(widget))); - final SlotWidget inventorySlot = new SlotWidget(inventoryHandler, 1) - .setFilter(stack -> stack.getItem() == poweredSpawnerItem); - - DynamicPositionedColumn configurationElements = new DynamicPositionedColumn(); - addConfigurationWidgets(configurationElements, buildContext, inventorySlot); - - builder.widget( - new DynamicPositionedColumn().setSynced(false) - .widget(inventorySlot) - .widget(new CycleButtonWidget().setToggle(() -> getBaseMetaTileEntity().isAllowedToWork(), works -> { - if (works) getBaseMetaTileEntity().enableWorking(); - else getBaseMetaTileEntity().disableWorking(); - - if (!(buildContext.getPlayer() instanceof EntityPlayerMP)) return; - String tChat = GT_Utility.trans("090", "Machine Processing: ") - + (works ? GT_Utility.trans("088", "Enabled") : GT_Utility.trans("087", "Disabled")); - if (hasAlternativeModeText()) tChat = getAlternativeModeText(); - GT_Utility.sendChatToPlayer(buildContext.getPlayer(), tChat); - }) - .addTooltip(0, new Text("Disabled").color(Color.RED.dark(3))) - .addTooltip(1, new Text("Enabled").color(Color.GREEN.dark(3))) - .setTextureGetter(toggleButtonTextureGetter) - .setBackground(GT_UITextures.BUTTON_STANDARD) - .setSize(18, 18) - .addTooltip("Working status")) - .widget(configurationElements.setEnabled(widget -> !getBaseMetaTileEntity().isActive())) - .widget( - new DrawableWidget().setDrawable(GT_UITextures.OVERLAY_BUTTON_CROSS) - .setSize(18, 18) - .addTooltip(new Text("Please stop the machine to configure it").color(Color.RED.dark(3))) - .setEnabled(widget -> getBaseMetaTileEntity().isActive())) - .setPos(151, 4)); - - final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); - drawTexts(screenElements, inventorySlot); - builder.widget(screenElements); - } - - private void addConfigurationWidgets(DynamicPositionedColumn configurationElements, UIBuildContext buildContext, - SlotWidget inventorySlot) { - configurationElements.setSynced(false); + protected void addConfigurationWidgets(DynamicPositionedColumn configurationElements, UIBuildContext buildContext) { + configurationElements.setSynced(true); configurationElements.widget(new CycleButtonWidget().setToggle(() -> isInRitualMode, v -> { if (this.mMaxProgresstime > 0) { GT_Utility.sendChatToPlayer(buildContext.getPlayer(), "Can't change mode when running !"); @@ -760,9 +704,10 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher } }) .setTextureGetter(toggleButtonTextureGetter) - .setBackground(GT_UITextures.BUTTON_STANDARD) - .setSize(18, 18) - .addTooltip("Ritual mode")); + .setVariableBackgroundGetter(toggleButtonBackgroundGetter) + .setSize(16, 16) + .addTooltip("Ritual mode") + .setTooltipShowUpDelay(TOOLTIP_DELAY)); configurationElements.widget(new CycleButtonWidget().setToggle(() -> mIsProducingInfernalDrops, v -> { if (this.mMaxProgresstime > 0) { GT_Utility.sendChatToPlayer(buildContext.getPlayer(), "Can't change mode when running !"); @@ -777,85 +722,30 @@ public class GT_MetaTileEntity_ExtremeEntityCrusher else GT_Utility.sendChatToPlayer(buildContext.getPlayer(), "Mobs can spawn infernal now"); }) .setTextureGetter(toggleButtonTextureGetter) - .setBackground(GT_UITextures.BUTTON_STANDARD) - .setSize(18, 18) + .setVariableBackgroundGetter(toggleButtonBackgroundGetter) + .setSize(16, 16) .addTooltip("Is allowed to spawn infernal mobs") - .addTooltip(new Text("Does not affect mobs that are always infernal !").color(Color.GRAY.normal))); + .addTooltip(new Text("Does not affect mobs that are always infernal !").color(Color.GRAY.normal)) + .setTooltipShowUpDelay(TOOLTIP_DELAY)); } @Override - protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { - screenElements.setSynced(false) - .setSpace(0) - .setPos(10, 7); - - screenElements.widget( - new DynamicPositionedRow().setSynced(false) - .widget(new TextWidget("Status: ").setDefaultColor(COLOR_TEXT_GRAY.get())) - .widget(new DynamicTextWidget(() -> { - if (getBaseMetaTileEntity().isActive()) return new Text("Working !").color(Color.GREEN.dark(3)); - else if (getBaseMetaTileEntity().isAllowedToWork()) - return new Text("Enabled").color(Color.GREEN.dark(3)); - else if (getBaseMetaTileEntity().wasShutdown()) - return new Text("Shutdown (CRITICAL)").color(Color.RED.dark(3)); - else return new Text("Disabled").color(Color.RED.dark(3)); - })) - .setEnabled(isFixed)); - screenElements.widget(new DynamicTextWidget(() -> { - ItemStack aStack = mInventory[1]; - if (aStack == null) return new Text("Insert Powered Spawner").color(Color.RED.dark(3)); - else { - Text invalid = new Text("Invalid Spawner").color(Color.RED.dark(3)); - if (aStack.getItem() != poweredSpawnerItem) return invalid; - - if (aStack.getTagCompound() == null) return invalid; - String mobType = aStack.getTagCompound() - .getString("mobType"); - if (mobType.isEmpty()) return invalid; - - if (!MobNameToRecipeMap.containsKey(mobType)) return invalid; - - return new Text(StatCollector.translateToLocal("entity." + mobType + ".name")) - .color(Color.GREEN.dark(3)); - } - }).setEnabled(isFixed)); - - screenElements - .widget( - new TextWidget(GT_Utility.trans("132", "Pipe is loose.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mWrench)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mWrench, val -> mWrench = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("133", "Screws are loose.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mScrewdriver)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mScrewdriver, val -> mScrewdriver = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("134", "Something is stuck.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mSoftHammer)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mSoftHammer, val -> mSoftHammer = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("135", "Platings are dented.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mHardHammer)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mHardHammer, val -> mHardHammer = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("136", "Circuitry burned out.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mSolderingTool)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mSolderingTool, val -> mSolderingTool = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("137", "That doesn't belong there.")) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mCrowbar)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mCrowbar, val -> mCrowbar = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("138", "Incomplete Structure.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mMachine)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mMachine, val -> mMachine = val)); + public void createInventorySlots() { + final SlotWidget spawnerSlot = new SlotWidget(inventoryHandler, 1); + spawnerSlot.setBackground( + GT_UITextures.SLOT_DARK_GRAY, + UITexture.fullImage(Tags.MODID, "gui/slot/gray_spawner") + .withFixedSize(16, 16) + .withOffset(1, 1)); + spawnerSlot.setFilter(stack -> stack.getItem() == poweredSpawnerItem); + slotWidgets.add(spawnerSlot); + final SlotWidget weaponSlot = new SlotWidget(weaponCache, 0); + weaponSlot.setBackground( + GT_UITextures.SLOT_DARK_GRAY, + UITexture.fullImage(Tags.MODID, "gui/slot/gray_sword") + .withFixedSize(16, 16) + .withOffset(1, 1)); + slotWidgets.add(weaponSlot); } private static class EECFakePlayer extends FakePlayer { diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeIndustrialGreenhouse.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeIndustrialGreenhouse.java index 164ba7e7ba..0ab7995f7a 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeIndustrialGreenhouse.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeIndustrialGreenhouse.java @@ -45,7 +45,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; import net.minecraft.block.Block; import net.minecraft.block.BlockFlower; @@ -81,31 +80,23 @@ import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; 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.Alignment; +import com.gtnewhorizons.modularui.api.drawable.shapes.Rectangle; import com.gtnewhorizons.modularui.api.math.Color; -import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.MainAxisAlignment; import com.gtnewhorizons.modularui.api.screen.ModularUIContext; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.builder.UIInfo; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; -import com.gtnewhorizons.modularui.common.widget.ChangeableWidget; import com.gtnewhorizons.modularui.common.widget.Column; import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; -import com.gtnewhorizons.modularui.common.widget.DynamicPositionedRow; -import com.gtnewhorizons.modularui.common.widget.DynamicTextWidget; import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; -import com.gtnewhorizons.modularui.common.widget.Scrollable; import com.gtnewhorizons.modularui.common.widget.SlotWidget; import com.gtnewhorizons.modularui.common.widget.TextWidget; -import com.kuba6000.mobsinfo.api.utils.ItemID; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; @@ -124,6 +115,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_MultiInput; import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; @@ -136,10 +128,9 @@ import ic2.api.crops.Crops; import ic2.core.Ic2Items; import ic2.core.crop.TileEntityCrop; import kubatech.Tags; +import kubatech.api.DynamicInventory; import kubatech.api.LoaderReference; -import kubatech.api.helpers.GTHelper; import kubatech.api.implementations.KubaTechGTMultiBlockBase; -import kubatech.api.utils.ModUtils; import kubatech.client.effect.CropRenderer; @SuppressWarnings("unused") @@ -150,6 +141,7 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse private static final int EIG_MATH_VERSION = 0; private static final int CONFIGURATION_WINDOW_ID = 999; + public final List<GreenHouseSlot> mStorage = new ArrayList<>(); private int oldVersion = 0; private int mCasing = 0; public int mMaxSlots = 0; @@ -445,7 +437,7 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse this.mEfficiencyIncrease = 10000; return CheckRecipeResultRegistry.SUCCESSFUL; } - if (mStorage.size() > mMaxSlots) return CheckRecipeResultRegistry.NO_RECIPE; + if (mStorage.size() > mMaxSlots) return SimpleCheckRecipeResult.ofFailure("EIG_slotoverflow"); if (mStorage.isEmpty()) return CheckRecipeResultRegistry.NO_RECIPE; waterusage = 0; @@ -474,7 +466,7 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse fluidsToUse.add(i); if (watercheck <= 0) break; } - if (watercheck > 0 && !debug) return CheckRecipeResultRegistry.NO_RECIPE; + if (watercheck > 0 && !debug) return SimpleCheckRecipeResult.ofFailure("EIG_missingwater"); watercheck = waterusage; for (GT_MetaTileEntity_Hatch_Input i : fluidsToUse) { int used = i.drain(watercheck, true).amount; @@ -515,12 +507,12 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse double multiplier = 1.d + (((double) boost / (double) maxboost) * 4d); if (isIC2Mode) { - if (glasTier < 6) return CheckRecipeResultRegistry.NO_RECIPE; + if (glasTier < 6) return SimpleCheckRecipeResult.ofFailure("EIG_ic2glass"); this.mMaxProgresstime = 100; List<ItemStack> outputs = new ArrayList<>(); for (int i = 0; i < Math.min(mMaxSlots, mStorage.size()); i++) outputs.addAll( mStorage.get(i) - .getIC2Drops(((double) this.mMaxProgresstime * 32d) * multiplier)); + .getIC2Drops(this, ((double) this.mMaxProgresstime * 32d) * multiplier)); this.mOutputItems = outputs.toArray(new ItemStack[0]); } else { this.mMaxProgresstime = Math.max(20, 100 / (tier - 3)); // Min 1 s @@ -561,30 +553,6 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse return valid; } - @Override - public boolean useModularUI() { - return true; - } - - @Override - public int getGUIHeight() { - return 166; - } - - @Override - public int getGUIWidth() { - return 176; - } - - @Override - public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.bindPlayerInventory( - buildContext.getPlayer(), - new Pos2d(7, 83), - this.getGUITextureSet() - .getItemSlot()); - } - private static final UIInfo<?, ?> GreenhouseUI = createKTMetaTileEntityUI( KT_ModulaUIContainer_ExtremeIndustrialGreenhouse::new); @@ -625,7 +593,7 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse GT_Utility.sendChatToPlayer(aPlayer, EnumChatFormatting.RED + "Can't insert while running !"); return super.transferStackInSlot(aPlayer, aSlotIndex); } - if (mte.addCrop(aStack)) { + if (mte.addCrop(aStack) != null) { if (aStack.stackSize == 0) s.putStack(null); else s.putStack(aStack); detectAndSendChanges(); @@ -635,281 +603,98 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse } } - List<GTHelper.StackableItemSlot> drawables = new ArrayList<>(); - private int usedSlots = 0; // mStorage.size() + @Override + protected void addConfigurationWidgets(DynamicPositionedColumn configurationElements, UIBuildContext buildContext) { + buildContext.addSyncedWindow(CONFIGURATION_WINDOW_ID, this::createConfigurationWindow); + configurationElements.setSynced(false); + configurationElements.widget( + new ButtonWidget().setOnClick( + (clickData, widget) -> { + if (!widget.isClient()) widget.getContext() + .openSyncedWindow(CONFIGURATION_WINDOW_ID); + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CYCLIC) + .addTooltip("Configuration") + .setSize(16, 16)); + } + + DynamicInventory<GreenHouseSlot> dynamicInventory = new DynamicInventory<>( + 128, + 60, + () -> mMaxSlots, + mStorage, + s -> s.input).allowInventoryInjection(this::addCrop) + .allowInventoryExtraction(mStorage::remove) + .allowInventoryReplace((i, stack) -> { + if (!isIC2Mode) { + GreenHouseSlot slot = mStorage.get(i); + if (GT_Utility.areStacksEqual(stack, slot.input)) { + if (slot.input.stackSize < 64) { + slot.addAll( + this.getBaseMetaTileEntity() + .getWorld(), + stack); + return stack; + } + return null; + } + if (!addCrop(stack, i, true)) return null; + slot = mStorage.remove(i); + addCrop(stack, i, false); + return slot.input; + } else { + if (stack.stackSize != 1) return null; + if (!addCrop(stack, i, true)) return null; + GreenHouseSlot slot = mStorage.remove(i); + addCrop(stack, i, false); + return slot.input; + } + }) + .setEnabled(() -> this.mMaxProgresstime == 0); - @SuppressWarnings("UnstableApiUsage") @Override - public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.widget( - new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) - .setPos(7, 4) - .setSize(143, 75) - .setEnabled(widget -> !isFixed.apply(widget))); + public void createInventorySlots() { - buildContext.addSyncedWindow(CONFIGURATION_WINDOW_ID, this::createConfigurationWindow); - EntityPlayer player = buildContext.getPlayer(); + } - // Slot is not needed + private boolean isInInventory = true; + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + isInInventory = !getBaseMetaTileEntity().isActive(); builder.widget( - new DynamicPositionedColumn().setSynced(false) - .widget(new CycleButtonWidget().setToggle(() -> getBaseMetaTileEntity().isAllowedToWork(), works -> { - if (works) getBaseMetaTileEntity().enableWorking(); - else getBaseMetaTileEntity().disableWorking(); - - if (!(player instanceof EntityPlayerMP)) return; - String tChat = GT_Utility.trans("090", "Machine Processing: ") - + (works ? GT_Utility.trans("088", "Enabled") : GT_Utility.trans("087", "Disabled")); - if (hasAlternativeModeText()) tChat = getAlternativeModeText(); - GT_Utility.sendChatToPlayer(player, tChat); - }) - .addTooltip(0, new Text("Disabled").color(Color.RED.dark(3))) - .addTooltip(1, new Text("Enabled").color(Color.GREEN.dark(3))) - .setTextureGetter(toggleButtonTextureGetter) - .setBackground(GT_UITextures.BUTTON_STANDARD) - .setSize(18, 18) - .addTooltip("Working status")) - .widget( - new ButtonWidget().setOnClick( - (clickData, widget) -> { - if (!widget.isClient()) widget.getContext() - .openSyncedWindow(CONFIGURATION_WINDOW_ID); - }) - .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CYCLIC) - .addTooltip("Configuration") - .setSize(18, 18)) - .setPos(151, 4)); - - ChangeableWidget cropsContainer = new ChangeableWidget(() -> createCropsContainerWidget(player)); - - AtomicInteger lastMaxSlots = new AtomicInteger(); - AtomicInteger lastUsedSlots = new AtomicInteger(); - builder.widget(cropsContainer.attachSyncer(new FakeSyncWidget.IntegerSyncer(() -> { - if (lastMaxSlots.get() != mMaxSlots) { - lastMaxSlots.set(mMaxSlots); - cropsContainer.notifyChangeNoSync(); - } - return mMaxSlots; - }, i -> { - if (mMaxSlots != i) { - mMaxSlots = i; - cropsContainer.notifyChangeNoSync(); - } - }), builder) - .attachSyncer(new FakeSyncWidget.IntegerSyncer(() -> { - if (lastUsedSlots.get() != mStorage.size()) { - lastUsedSlots.set(mStorage.size()); - cropsContainer.notifyChangeNoSync(); - } - return mStorage.size(); - }, i -> { - if (usedSlots != i) { - usedSlots = i; - cropsContainer.notifyChangeNoSync(); - } - }), builder) - .attachSyncer(new FakeSyncWidget.ListSyncer<>(() -> { - HashMap<ItemID, Integer> itemMap = new HashMap<>(); - HashMap<ItemID, ItemStack> stackMap = new HashMap<>(); - HashMap<ItemID, ArrayList<Integer>> realSlotMap = new HashMap<>(); - for (int i = 0, mStorageSize = mStorage.size(); i < mStorageSize; i++) { - GreenHouseSlot slot = mStorage.get(i); - ItemID id = ItemID.createNoCopy(slot.input, false); - itemMap.merge(id, 1, Integer::sum); - stackMap.putIfAbsent(id, slot.input); - realSlotMap.computeIfAbsent(id, unused -> new ArrayList<>()) - .add(i); - } - List<GTHelper.StackableItemSlot> newDrawables = new ArrayList<>(); - for (Map.Entry<ItemID, Integer> entry : itemMap.entrySet()) { - newDrawables.add( - new GTHelper.StackableItemSlot( - entry.getValue(), - stackMap.get(entry.getKey()), - realSlotMap.get(entry.getKey()))); - } - if (!Objects.equals(newDrawables, drawables)) { - drawables = newDrawables; - cropsContainer.notifyChangeNoSync(); - } - return drawables; - }, l -> { - drawables.clear(); - drawables.addAll(l); - cropsContainer.notifyChangeNoSync(); - }, (buffer, i) -> { - try { - i.write(buffer); - } catch (IOException e) { - throw new RuntimeException(e); - } - }, buffer -> { - try { - return GTHelper.StackableItemSlot.read(buffer); - } catch (IOException e) { - throw new RuntimeException(e); - } - }), builder)); + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(4, 4) + .setSize(190, 85) + .setEnabled(w -> !isInInventory)); + builder.widget( + dynamicInventory.asWidget(builder, buildContext) + .setPos(10, 16) + .setBackground(new Rectangle().setColor(Color.rgb(163, 163, 198))) + .setEnabled(w -> isInInventory)); + builder.widget( + new CycleButtonWidget().setToggle(() -> isInInventory, i -> isInInventory = i) + .setTextureGetter(i -> i == 0 ? new Text("Inventory") : new Text("Status")) + .setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(140, 4) + .setSize(55, 16)); final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); drawTexts(screenElements, null); - builder.widget(screenElements); - } + builder.widget(screenElements.setEnabled(w -> !isInInventory)); - protected Widget createCropsContainerWidget(EntityPlayer player) { - Scrollable cropsContainer = new Scrollable().setVerticalScroll(); - - ArrayList<Widget> buttons = new ArrayList<>(); - - if (!ModUtils.isClientThreaded()) { - HashMap<ItemID, Integer> itemMap = new HashMap<>(); - HashMap<ItemID, ItemStack> stackMap = new HashMap<>(); - HashMap<ItemID, ArrayList<Integer>> realSlotMap = new HashMap<>(); - for (int i = 0, mStorageSize = mStorage.size(); i < mStorageSize; i++) { - GreenHouseSlot slot = mStorage.get(i); - ItemID id = ItemID.createNoCopy(slot.input, false); - itemMap.merge(id, 1, Integer::sum); - stackMap.putIfAbsent(id, slot.input); - realSlotMap.computeIfAbsent(id, unused -> new ArrayList<>()) - .add(i); - } - drawables = new ArrayList<>(); - for (Map.Entry<ItemID, Integer> entry : itemMap.entrySet()) { - drawables.add( - new GTHelper.StackableItemSlot( - entry.getValue(), - stackMap.get(entry.getKey()), - realSlotMap.get(entry.getKey()))); - } - } + builder.widget(createPowerSwitchButton(builder)) + .widget(createVoidExcessButton(builder)) + .widget(createInputSeparationButton(builder)) + .widget(createBatchModeButton(builder)) + .widget(createLockToSingleRecipeButton(builder)); - for (int ID = 0; ID < drawables.size(); ID++) { - final int finalID = ID; - buttons.add(new ButtonWidget().setOnClick((clickData, widget) -> { - if (!(player instanceof EntityPlayerMP)) return; - if (!clickData.shift) { - ItemStack input = player.inventory.getItemStack(); - if (input != null) { - if (this.mMaxProgresstime > 0) { - GT_Utility - .sendChatToPlayer(player, EnumChatFormatting.RED + "Can't replace while running !"); - return; - } - if (addCrop(input, -1, true)) { - if (drawables.size() > finalID) { - int realID = drawables.get(finalID).realSlots.get(0); - GreenHouseSlot removed = mStorage.remove(realID); - addCrop(input, realID, false); - player.inventory.setItemStack(removed.input); - // force widget update?? - } else { - if (input.stackSize == 0) addCrop(input); - player.inventory.setItemStack(null); - } - ((EntityPlayerMP) player).isChangingQuantityOnly = false; - ((EntityPlayerMP) player).updateHeldItem(); - } - return; - } - } - if (drawables.size() <= finalID) return; - if (this.mMaxProgresstime > 0) { - GT_Utility.sendChatToPlayer(player, EnumChatFormatting.RED + "Can't eject while running !"); - return; - } - int realID = drawables.get(finalID).realSlots.get(0); - GreenHouseSlot removed = mStorage.remove(realID); - if (clickData.shift) { - if (player.inventory.addItemStackToInventory(removed.input)) { - player.inventoryContainer.detectAndSendChanges(); - return; - } - } - if (clickData.mouseButton == 1) { - if (player.inventory.getItemStack() == null) { - player.inventory.setItemStack(removed.input); - ((EntityPlayerMP) player).isChangingQuantityOnly = false; - ((EntityPlayerMP) player).updateHeldItem(); - return; - } - } - addOutput(removed.input); - GT_Utility.sendChatToPlayer(player, "Crop ejected !"); - }) - .setBackground( - () -> new IDrawable[] { getBaseMetaTileEntity().getGUITextureSet() - .getItemSlot(), - new ItemDrawable(drawables.size() > finalID ? drawables.get(finalID).stack : null) - .withFixedSize(16, 16, 1, 1), - new Text( - drawables.size() > finalID ? (drawables.get(finalID).count > 99 ? "+99" - : String.valueOf(drawables.get(finalID).count)) : "").color(Color.PURPLE.normal) - .alignment(Alignment.TopRight), - new Text( - drawables.size() > finalID ? String.valueOf(drawables.get(finalID).stack.stackSize) : "") - .color(Color.WHITE.normal) - .shadow() - .alignment(Alignment.BottomRight) }) - .dynamicTooltip(() -> { - if (drawables.size() > finalID) return Arrays.asList( - "x" + drawables.get(finalID).stack.stackSize - + " " - + drawables.get(finalID).stack.getDisplayName(), - EnumChatFormatting.DARK_PURPLE + "There are " - + drawables.get(finalID).count - + " identical slots", - EnumChatFormatting.GRAY + "Left click to eject into input bus", - EnumChatFormatting.GRAY + "Right click to get into mouse", - EnumChatFormatting.GRAY + "Shift click to get into inventory", - EnumChatFormatting.GRAY + "Click with other crop in mouse to replace"); - return Collections.emptyList(); - }) - .setSize(18, 18)); - } + DynamicPositionedColumn configurationElements = new DynamicPositionedColumn(); + addConfigurationWidgets(configurationElements, buildContext); - buttons.add(new ButtonWidget().setOnClick((clickData, widget) -> { - if (!(player instanceof EntityPlayerMP)) return; - ItemStack input = player.inventory.getItemStack(); - if (input != null) { - if (this.mMaxProgresstime > 0) { - GT_Utility.sendChatToPlayer(player, EnumChatFormatting.RED + "Can't insert while running !"); - return; - } - if (addCrop(input)) { - if (input.stackSize == 0) player.inventory.setItemStack(null); - ((EntityPlayerMP) player).isChangingQuantityOnly = false; - ((EntityPlayerMP) player).updateHeldItem(); - } - } - }) - .setBackground( - () -> new IDrawable[] { getBaseMetaTileEntity().getGUITextureSet() - .getItemSlot(), - new Text(String.valueOf((mMaxSlots - usedSlots) > 99 ? "+99" : (mMaxSlots - usedSlots))) - .color(Color.PURPLE.normal) - .alignment(Alignment.TopRight) }) - .dynamicTooltip( - () -> Arrays.asList( - EnumChatFormatting.GRAY + "Empty slot", - EnumChatFormatting.DARK_PURPLE + "There are " + (mMaxSlots - usedSlots) + " identical slots", - EnumChatFormatting.GRAY + "Click with crop in mouse to insert", - EnumChatFormatting.GRAY + "Shift click a crop in your inventory to insert")) - .setSize(18, 18)); - - final int perRow = 7; - for (int i = 0, imax = ((buttons.size() - 1) / perRow); i <= imax; i++) { - DynamicPositionedRow row = new DynamicPositionedRow().setSynced(false); - for (int j = 0, jmax = (i == imax ? (buttons.size() - 1) % perRow : (perRow - 1)); j <= jmax; j++) { - final int finalI = i * perRow; - final int finalJ = j; - final int ID = finalI + finalJ; - row.widget(buttons.get(ID)); - } - cropsContainer.widget(row.setPos(0, i * 18)); - } - return cropsContainer.setPos(10, 16) - .setSize(128, 60); + builder.widget( + configurationElements.setAlignment(MainAxisAlignment.END) + .setPos(getPowerSwitchButtonPos().subtract(0, 18))); } protected ModularWindow createConfigurationWindow(final EntityPlayer player) { @@ -1027,61 +812,75 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse return builder.build(); } + private HashMap<ItemStack, Double> GUIDropProgress = new HashMap<>(); + + @Override + protected String generateCurrentRecipeInfoString() { + if (!isIC2Mode) return super.generateCurrentRecipeInfoString(); + StringBuilder ret = new StringBuilder(EnumChatFormatting.WHITE + "Progress: ") + .append(String.format("%,.2f", (double) mProgresstime / 20)) + .append("s / ") + .append(String.format("%,.2f", (double) mMaxProgresstime / 20)) + .append("s (") + .append(String.format("%,.1f", (double) mProgresstime / mMaxProgresstime * 100)) + .append("%)\n"); + + for (Map.Entry<ItemStack, Double> drop : GUIDropProgress.entrySet()) { + ret.append( + drop.getKey() + .getDisplayName()) + .append(": ") + .append( + String.format( + "%.2f (+%d)\n", + drop.getValue(), + Arrays.stream(mOutputItems) + .filter(s -> s.isItemEqual(drop.getKey())) + .mapToInt(i -> i.stackSize) + .sum())); + } + + return ret.toString(); + } + @Override protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { - screenElements.setSynced(false) - .setSpace(0) - .setPos(10, 7); - - screenElements.widget( - new DynamicPositionedRow().setSynced(false) - .widget(new TextWidget("Status: ").setDefaultColor(COLOR_TEXT_GRAY.get())) - .widget(new DynamicTextWidget(() -> { - if (getBaseMetaTileEntity().isActive()) return new Text("Working !").color(Color.GREEN.dark(3)); - else if (getBaseMetaTileEntity().isAllowedToWork()) - return new Text("Enabled").color(Color.GREEN.dark(3)); - else if (getBaseMetaTileEntity().wasShutdown()) - return new Text("Shutdown (CRITICAL)").color(Color.RED.dark(3)); - else return new Text("Disabled").color(Color.RED.dark(3)); - })) - .setEnabled(isFixed)); - - screenElements - .widget( - new TextWidget(GT_Utility.trans("132", "Pipe is loose.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mWrench)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mWrench, val -> mWrench = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("133", "Screws are loose.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mScrewdriver)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mScrewdriver, val -> mScrewdriver = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("134", "Something is stuck.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mSoftHammer)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mSoftHammer, val -> mSoftHammer = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("135", "Platings are dented.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mHardHammer)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mHardHammer, val -> mHardHammer = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("136", "Circuitry burned out.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mSolderingTool)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mSolderingTool, val -> mSolderingTool = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("137", "That doesn't belong there.")) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mCrowbar)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mCrowbar, val -> mCrowbar = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("138", "Incomplete Structure.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mMachine)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mMachine, val -> mMachine = val)); + screenElements.widget(new FakeSyncWidget.BooleanSyncer(() -> isIC2Mode, b -> isIC2Mode = b)); + screenElements.widget(new FakeSyncWidget<>(() -> { + HashMap<ItemStack, Double> ret = new HashMap<>(); + HashMap<String, Double> dropProgress = new HashMap<>(); + + for (Map.Entry<String, Double> drop : dropprogress.entrySet()) { + dropProgress.merge(drop.getKey(), drop.getValue(), Double::sum); + } + + for (Map.Entry<String, Double> drop : dropProgress.entrySet()) { + ret.put(GreenHouseSlot.dropstacks.get(drop.getKey()), drop.getValue()); + } + return ret; + }, h -> GUIDropProgress = h, (buffer, h) -> { + buffer.writeVarIntToBuffer(h.size()); + for (Map.Entry<ItemStack, Double> itemStackDoubleEntry : h.entrySet()) { + try { + buffer.writeItemStackToBuffer(itemStackDoubleEntry.getKey()); + buffer.writeDouble(itemStackDoubleEntry.getValue()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }, buffer -> { + int len = buffer.readVarIntFromBuffer(); + HashMap<ItemStack, Double> ret = new HashMap<>(len); + for (int i = 0; i < len; i++) { + try { + ret.put(buffer.readItemStackFromBuffer(), buffer.readDouble()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return ret; + })); + super.drawTexts(screenElements, inventorySlot); } @Override @@ -1147,8 +946,6 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_INDEX) }; } - public final List<GreenHouseSlot> mStorage = new ArrayList<>(); - private boolean addCrop(ItemStack input, int slot, boolean simulate) { if (!isIC2Mode && !simulate) for (GreenHouseSlot g : mStorage) if (g.input.stackSize < 64 && GT_Utility.areStacksEqual(g.input, input)) { @@ -1169,10 +966,13 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse return false; } - private boolean addCrop(ItemStack input) { - return addCrop(input, -1, false); + private ItemStack addCrop(ItemStack input) { + if (addCrop(input, -1, false)) return input; + return null; } + final Map<String, Double> dropprogress = new HashMap<>(); + private static class GreenHouseSlot extends InventoryCrafting { final ItemStack input; @@ -1526,10 +1326,10 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse return drops; } - final Map<String, Double> dropprogress = new HashMap<>(); static final Map<String, ItemStack> dropstacks = new HashMap<>(); - public List<ItemStack> getIC2Drops(double timeelapsed) { + public List<ItemStack> getIC2Drops(GT_MetaTileEntity_ExtremeIndustrialGreenhouse tileEntity, + double timeelapsed) { int r = rn.nextInt(10); if (generations.size() <= r) return new ArrayList<>(); double growthPercent = (timeelapsed / (double) growthticks); @@ -1539,13 +1339,11 @@ public class GT_MetaTileEntity_ExtremeIndustrialGreenhouse for (ItemStack s : copied) { double pro = ((double) s.stackSize * growthPercent); s.stackSize = 1; - if (dropprogress.containsKey(s.toString())) - dropprogress.put(s.toString(), dropprogress.get(s.toString()) + pro); - else dropprogress.put(s.toString(), pro); + tileEntity.dropprogress.merge(s.toString(), pro, Double::sum); if (!dropstacks.containsKey(s.toString())) dropstacks.put(s.toString(), s.copy()); } copied.clear(); - for (Map.Entry<String, Double> entry : dropprogress.entrySet()) if (entry.getValue() >= 1d) { + for (Map.Entry<String, Double> entry : tileEntity.dropprogress.entrySet()) if (entry.getValue() >= 1d) { copied.add( dropstacks.get(entry.getKey()) .copy()); diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java index 360ea1ee65..1b519179d7 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java @@ -50,8 +50,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -77,28 +75,21 @@ import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; 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.Alignment; +import com.gtnewhorizons.modularui.api.drawable.shapes.Rectangle; import com.gtnewhorizons.modularui.api.math.Color; -import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.MainAxisAlignment; import com.gtnewhorizons.modularui.api.screen.ModularUIContext; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.builder.UIInfo; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; -import com.gtnewhorizons.modularui.common.widget.ChangeableWidget; import com.gtnewhorizons.modularui.common.widget.Column; import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; -import com.gtnewhorizons.modularui.common.widget.DynamicPositionedRow; -import com.gtnewhorizons.modularui.common.widget.DynamicTextWidget; import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; -import com.gtnewhorizons.modularui.common.widget.Scrollable; import com.gtnewhorizons.modularui.common.widget.SlotWidget; import com.gtnewhorizons.modularui.common.widget.TextWidget; import com.kuba6000.mobsinfo.api.utils.ItemID; @@ -126,14 +117,14 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; import kubatech.Tags; +import kubatech.api.DynamicInventory; import kubatech.api.LoaderReference; -import kubatech.api.helpers.GTHelper; import kubatech.api.implementations.KubaTechGTMultiBlockBase; -import kubatech.api.utils.ModUtils; import kubatech.client.effect.MegaApiaryBeesRenderer; public class GT_MetaTileEntity_MegaIndustrialApiary @@ -494,9 +485,10 @@ public class GT_MetaTileEntity_MegaIndustrialApiary mStorage.forEach(s -> s.generate(w, t)); } - if (mStorage.size() > mMaxSlots) return CheckRecipeResultRegistry.NO_RECIPE; + if (mStorage.size() > mMaxSlots) + return SimpleCheckRecipeResult.ofFailure("MegaApiary_slotoverflow"); - if (flowersError) return CheckRecipeResultRegistry.NO_RECIPE; + if (flowersError) return SimpleCheckRecipeResult.ofFailure("MegaApiary_noflowers"); if (needsTVarUpdate) { float t = (float) getVoltageTierExact(); @@ -525,7 +517,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary List<ItemStack> stacks = new ArrayList<>(); for (int i = 0, mStorageSize = Math.min(mStorage.size(), mMaxSlots); i < mStorageSize; i++) { BeeSimulator beeSimulator = mStorage.get(i); - stacks.addAll(beeSimulator.getDrops(64_00d * boosted)); + stacks.addAll(beeSimulator.getDrops(this, 64_00d * boosted)); } this.lEUt = -(int) ((double) GT_Values.V[6] * (double) mMaxSlots * 0.99d); @@ -639,30 +631,6 @@ public class GT_MetaTileEntity_MegaIndustrialApiary return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_INDEX) }; } - @Override - public boolean useModularUI() { - return true; - } - - @Override - public int getGUIHeight() { - return 166; - } - - @Override - public int getGUIWidth() { - return 176; - } - - @Override - public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.bindPlayerInventory( - buildContext.getPlayer(), - new Pos2d(7, 83), - this.getGUITextureSet() - .getItemSlot()); - } - private static final UIInfo<?, ?> MegaApiaryUI = createKTMetaTileEntityUI( KT_ModulaUIContainer_MegaIndustrialApiary::new); @@ -720,311 +688,94 @@ public class GT_MetaTileEntity_MegaIndustrialApiary } } - private List<GTHelper.StackableItemSlot> drawables = new ArrayList<>(); - private int usedSlots = 0; // mStorage.size() + DynamicInventory<BeeSimulator> dynamicInventory = new DynamicInventory<>( + 128, + 60, + () -> mMaxSlots, + mStorage, + s -> s.queenStack).allowInventoryInjection(input -> { + World w = getBaseMetaTileEntity().getWorld(); + float t = (float) getVoltageTierExact(); + BeeSimulator bs = new BeeSimulator(input, w, t); + if (bs.isValid) { + mStorage.add(bs); + return input; + } + return null; + }) + .allowInventoryExtraction(mStorage::remove) + .allowInventoryReplace((i, stack) -> { + if (stack.stackSize != 1) return null; + World w = getBaseMetaTileEntity().getWorld(); + float t = (float) getVoltageTierExact(); + BeeSimulator bs = new BeeSimulator(stack, w, t); + if (bs.isValid) { + BeeSimulator removed = mStorage.remove(i); + mStorage.add(i, bs); + return removed.queenStack; + } + return null; + }) + .setEnabled(() -> this.mMaxProgresstime == 0); - @SuppressWarnings("UnstableApiUsage") @Override - public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.widget( - new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) - .setPos(7, 4) - .setSize(143, 75) - .setEnabled(widget -> !isFixed.apply(widget))); + public void createInventorySlots() { - buildContext.addSyncedWindow(CONFIGURATION_WINDOW_ID, this::createConfigurationWindow); - EntityPlayer player = buildContext.getPlayer(); + } - // Slot is not needed + private boolean isInInventory = true; + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + isInInventory = !getBaseMetaTileEntity().isActive(); builder.widget( - new DynamicPositionedColumn().setSynced(false) - .widget(new CycleButtonWidget().setToggle(() -> getBaseMetaTileEntity().isAllowedToWork(), works -> { - if (works) getBaseMetaTileEntity().enableWorking(); - else getBaseMetaTileEntity().disableWorking(); - - if (!(player instanceof EntityPlayerMP)) return; - String tChat = GT_Utility.trans("090", "Machine Processing: ") - + (works ? GT_Utility.trans("088", "Enabled") : GT_Utility.trans("087", "Disabled")); - if (hasAlternativeModeText()) tChat = getAlternativeModeText(); - GT_Utility.sendChatToPlayer(player, tChat); - }) - .addTooltip(0, new Text("Disabled").color(Color.RED.dark(3))) - .addTooltip(1, new Text("Enabled").color(Color.GREEN.dark(3))) - .setTextureGetter(toggleButtonTextureGetter) - .setBackground(GT_UITextures.BUTTON_STANDARD) - .setSize(18, 18) - .addTooltip("Working status")) - .widget( - new ButtonWidget().setOnClick( - (clickData, widget) -> { - if (!widget.isClient()) widget.getContext() - .openSyncedWindow(CONFIGURATION_WINDOW_ID); - }) - .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CYCLIC) - .addTooltip("Configuration") - .setSize(18, 18)) - .setPos(151, 4)); - - ChangeableWidget beesContainer = new ChangeableWidget(() -> createBeesContainerWidget(player)); - - AtomicInteger lastMaxSlots = new AtomicInteger(); - AtomicInteger lastUsedSlots = new AtomicInteger(); - builder.widget(beesContainer.attachSyncer(new FakeSyncWidget.IntegerSyncer(() -> { - if (lastMaxSlots.get() != mMaxSlots) { - lastMaxSlots.set(mMaxSlots); - beesContainer.notifyChangeNoSync(); - } - return mMaxSlots; - }, i -> { - if (mMaxSlots != i) { - mMaxSlots = i; - beesContainer.notifyChangeNoSync(); - } - }), builder) - .attachSyncer(new FakeSyncWidget.IntegerSyncer(() -> { - if (lastUsedSlots.get() != mStorage.size()) { - lastUsedSlots.set(mStorage.size()); - beesContainer.notifyChangeNoSync(); - } - return mStorage.size(); - }, i -> { - if (usedSlots != i) { - usedSlots = i; - beesContainer.notifyChangeNoSync(); - } - }), builder) - .attachSyncer(new FakeSyncWidget.ListSyncer<>(() -> { - HashMap<ItemID, Integer> itemMap = new HashMap<>(); - HashMap<ItemID, ItemStack> stackMap = new HashMap<>(); - HashMap<ItemID, ArrayList<Integer>> realSlotMap = new HashMap<>(); - for (int i = 0, mStorageSize = mStorage.size(); i < mStorageSize; i++) { - BeeSimulator slot = mStorage.get(i); - ItemID id = ItemID.createNoCopy(slot.queenStack, false); - itemMap.merge(id, 1, Integer::sum); - stackMap.putIfAbsent(id, slot.queenStack); - realSlotMap.computeIfAbsent(id, unused -> new ArrayList<>()) - .add(i); - } - List<GTHelper.StackableItemSlot> newDrawables = new ArrayList<>(); - for (Map.Entry<ItemID, Integer> entry : itemMap.entrySet()) { - newDrawables.add( - new GTHelper.StackableItemSlot( - entry.getValue(), - stackMap.get(entry.getKey()), - realSlotMap.get(entry.getKey()))); - } - if (!Objects.equals(newDrawables, drawables)) { - drawables = newDrawables; - beesContainer.notifyChangeNoSync(); - } - return drawables; - }, l -> { - drawables.clear(); - drawables.addAll(l); - beesContainer.notifyChangeNoSync(); - }, (buffer, i) -> { - try { - i.write(buffer); - } catch (IOException e) { - throw new RuntimeException(e); - } - }, buffer -> { - try { - return GTHelper.StackableItemSlot.read(buffer); - } catch (IOException e) { - throw new RuntimeException(e); - } - }), builder) - .attachSyncer(new FakeSyncWidget.ListSyncer<>(() -> { - if (flowersError) { - List<String> s = flowersCheck.stream() - .map(flowersCache::get) - .filter(Objects::nonNull) - .sorted() - .collect(Collectors.toList()); - s.add(0, "Missing flower types:"); - return s; - } else return Collections.emptyList(); - }, f -> flowersGUI = f, (b, e) -> { - try { - b.writeStringToBuffer(e); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - }, b -> { - try { - return b.readStringFromBuffer(999); - } catch (IOException e) { - throw new RuntimeException(e); - } - }), builder)); + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(4, 4) + .setSize(190, 85) + .setEnabled(w -> !isInInventory)); + builder.widget( + dynamicInventory.asWidget(builder, buildContext) + .setPos(10, 16) + .setBackground(new Rectangle().setColor(Color.rgb(163, 163, 198))) + .setEnabled(w -> isInInventory)); + builder.widget( + new CycleButtonWidget().setToggle(() -> isInInventory, i -> isInInventory = i) + .setTextureGetter(i -> i == 0 ? new Text("Inventory") : new Text("Status")) + .setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(140, 4) + .setSize(55, 16)); final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); drawTexts(screenElements, null); - builder.widget(screenElements); - } - - private Widget createBeesContainerWidget(EntityPlayer player) { - Scrollable beesContainer = new Scrollable().setVerticalScroll(); - - ArrayList<Widget> buttons = new ArrayList<>(); - - if (!ModUtils.isClientThreaded()) { - HashMap<ItemID, Integer> itemMap = new HashMap<>(); - HashMap<ItemID, ItemStack> stackMap = new HashMap<>(); - HashMap<ItemID, ArrayList<Integer>> realSlotMap = new HashMap<>(); - for (int i = 0, mStorageSize = mStorage.size(); i < mStorageSize; i++) { - BeeSimulator slot = mStorage.get(i); - ItemID id = ItemID.createNoCopy(slot.queenStack, false); - itemMap.merge(id, 1, Integer::sum); - stackMap.putIfAbsent(id, slot.queenStack); - realSlotMap.computeIfAbsent(id, unused -> new ArrayList<>()) - .add(i); - } - drawables = new ArrayList<>(); - for (Map.Entry<ItemID, Integer> entry : itemMap.entrySet()) { - drawables.add( - new GTHelper.StackableItemSlot( - entry.getValue(), - stackMap.get(entry.getKey()), - realSlotMap.get(entry.getKey()))); - } - } + builder.widget(screenElements.setEnabled(w -> !isInInventory)); - for (int ID = 0; ID < drawables.size(); ID++) { - final int finalID = ID; - buttons.add(new ButtonWidget().setOnClick((clickData, widget) -> { - if (!(player instanceof EntityPlayerMP)) return; - if (!clickData.shift) { - ItemStack input = player.inventory.getItemStack(); - if (input != null) { - if (this.mMaxProgresstime > 0) { - GT_Utility - .sendChatToPlayer(player, EnumChatFormatting.RED + "Can't replace while running !"); - return; - } - if (beeRoot.getType(input) == EnumBeeType.QUEEN) { - World w = getBaseMetaTileEntity().getWorld(); - float t = (float) getVoltageTierExact(); - BeeSimulator bs = new BeeSimulator(input, w, t); - if (bs.isValid) { - if (mStorage.size() > finalID) { - int realID = drawables.get(finalID).realSlots.get(0); - BeeSimulator removed = mStorage.remove(realID); - mStorage.add(realID, bs); - player.inventory.setItemStack(removed.queenStack); - } else { - mStorage.add(bs); - player.inventory.setItemStack(null); - } - ((EntityPlayerMP) player).isChangingQuantityOnly = false; - ((EntityPlayerMP) player).updateHeldItem(); + builder.widget(createPowerSwitchButton(builder)) + .widget(createVoidExcessButton(builder)) + .widget(createInputSeparationButton(builder)) + .widget(createBatchModeButton(builder)) + .widget(createLockToSingleRecipeButton(builder)); - isCacheDirty = true; - } - } - return; - } - } + DynamicPositionedColumn configurationElements = new DynamicPositionedColumn(); + addConfigurationWidgets(configurationElements, buildContext); - if (mStorage.size() <= finalID) return; - if (this.mMaxProgresstime > 0) { - GT_Utility.sendChatToPlayer(player, EnumChatFormatting.RED + "Can't eject while running !"); - return; - } - int realID = drawables.get(finalID).realSlots.get(0); - BeeSimulator removed = mStorage.remove(realID); - isCacheDirty = true; - if (clickData.shift) { - if (player.inventory.addItemStackToInventory(removed.queenStack)) { - player.inventoryContainer.detectAndSendChanges(); - return; - } - } - if (clickData.mouseButton == 1) { - if (player.inventory.getItemStack() == null) { - player.inventory.setItemStack(removed.queenStack); - ((EntityPlayerMP) player).isChangingQuantityOnly = false; - ((EntityPlayerMP) player).updateHeldItem(); - return; - } - } + builder.widget( + configurationElements.setAlignment(MainAxisAlignment.END) + .setPos(getPowerSwitchButtonPos().subtract(0, 18))); + } - addOutput(removed.queenStack); - GT_Utility.sendChatToPlayer(player, "Queen ejected !"); - }) - .setBackground( - () -> new IDrawable[] { getBaseMetaTileEntity().getGUITextureSet() - .getItemSlot(), - new ItemDrawable(drawables.size() > finalID ? drawables.get(finalID).stack : null) - .withFixedSize(16, 16, 1, 1), - new Text( - drawables.size() > finalID ? (drawables.get(finalID).count > 99 ? "+99" - : String.valueOf(drawables.get(finalID).count)) : "").color(Color.PURPLE.normal) - .alignment(Alignment.TopRight) }) - .dynamicTooltip(() -> { - if (drawables.size() > finalID) return Arrays.asList( - drawables.get(finalID).stack.getDisplayName(), - EnumChatFormatting.DARK_PURPLE + "There are " - + drawables.get(finalID).count - + " identical slots", - EnumChatFormatting.GRAY + "Left click to eject into input bus", - EnumChatFormatting.GRAY + "Right click to get into mouse", - EnumChatFormatting.GRAY + "Shift click to get into inventory", - EnumChatFormatting.GRAY + "Click with other queen in mouse to replace"); - return Collections.emptyList(); + @Override + protected void addConfigurationWidgets(DynamicPositionedColumn configurationElements, UIBuildContext buildContext) { + buildContext.addSyncedWindow(CONFIGURATION_WINDOW_ID, this::createConfigurationWindow); + configurationElements.setSynced(false); + configurationElements.widget( + new ButtonWidget().setOnClick( + (clickData, widget) -> { + if (!widget.isClient()) widget.getContext() + .openSyncedWindow(CONFIGURATION_WINDOW_ID); }) - .setSize(18, 18)); - } - - buttons.add(new ButtonWidget().setOnClick((clickData, widget) -> { - if (!(player instanceof EntityPlayerMP)) return; - ItemStack input = player.inventory.getItemStack(); - if (input != null) { - if (this.mMaxProgresstime > 0) { - GT_Utility.sendChatToPlayer(player, EnumChatFormatting.RED + "Can't insert while running !"); - return; - } - World w = getBaseMetaTileEntity().getWorld(); - float t = (float) getVoltageTierExact(); - BeeSimulator bs = new BeeSimulator(input, w, t); - if (bs.isValid) { - mStorage.add(bs); - player.inventory.setItemStack(null); - ((EntityPlayerMP) player).isChangingQuantityOnly = false; - ((EntityPlayerMP) player).updateHeldItem(); - } - } - }) - .setBackground( - () -> new IDrawable[] { getBaseMetaTileEntity().getGUITextureSet() - .getItemSlot(), GT_UITextures.OVERLAY_SLOT_BEE_QUEEN, - new Text(String.valueOf((mMaxSlots - usedSlots) > 99 ? "+99" : (mMaxSlots - usedSlots))) - .color(Color.PURPLE.normal) - .alignment(Alignment.TopRight) }) - .dynamicTooltip( - () -> Arrays.asList( - EnumChatFormatting.GRAY + "Empty slot", - EnumChatFormatting.DARK_PURPLE + "There are " + (mMaxSlots - usedSlots) + " identical slots", - EnumChatFormatting.GRAY + "Click with queen in mouse to insert", - EnumChatFormatting.GRAY + "Shift click a queen in your inventory to insert")) - .setSize(18, 18)); - - final int perRow = 7; - for (int i = 0, imax = ((buttons.size() - 1) / perRow); i <= imax; i++) { - DynamicPositionedRow row = new DynamicPositionedRow().setSynced(false); - for (int j = 0, jmax = (i == imax ? (buttons.size() - 1) % perRow : (perRow - 1)); j <= jmax; j++) { - final int finalI = i * perRow; - final int finalJ = j; - final int ID = finalI + finalJ; - row.widget(buttons.get(ID)); - } - beesContainer.widget(row.setPos(0, i * 18)); - } - beesContainer.setPos(10, 16) - .setSize(128, 60); - return beesContainer; + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CYCLIC) + .addTooltip("Configuration") + .setSize(16, 16)); } protected ModularWindow createConfigurationWindow(final EntityPlayer player) { @@ -1126,67 +877,82 @@ public class GT_MetaTileEntity_MegaIndustrialApiary return builder.build(); } - private List<String> flowersGUI = Collections.emptyList(); + // private List<String> flowersGUI = Collections.emptyList(); + + private HashMap<ItemStack, Double> GUIDropProgress = new HashMap<>(); + + @Override + protected String generateCurrentRecipeInfoString() { + if (mSecondaryMode == 1) return super.generateCurrentRecipeInfoString(); + StringBuilder ret = new StringBuilder(EnumChatFormatting.WHITE + "Progress: ") + .append(String.format("%,.2f", (double) mProgresstime / 20)) + .append("s / ") + .append(String.format("%,.2f", (double) mMaxProgresstime / 20)) + .append("s (") + .append(String.format("%,.1f", (double) mProgresstime / mMaxProgresstime * 100)) + .append("%)\n"); + + for (Map.Entry<ItemStack, Double> drop : GUIDropProgress.entrySet()) { + ret.append( + drop.getKey() + .getDisplayName()) + .append(": ") + .append( + String.format( + "%.2f (+%d)\n", + drop.getValue(), + Arrays.stream(mOutputItems) + .filter(s -> s.isItemEqual(drop.getKey())) + .mapToInt(i -> i.stackSize) + .sum())); + } + + return ret.toString(); + } @Override protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { - screenElements.setSynced(false) - .setSpace(0) - .setPos(10, 7); - - screenElements.widget( - new DynamicPositionedRow().setSynced(false) - .widget(new TextWidget("Status: ").setDefaultColor(COLOR_TEXT_GRAY.get())) - .widget(new DynamicTextWidget(() -> { - if (flowersError) return new Text("Missing flowers!").color(Color.RED.dark(3)); - if (getBaseMetaTileEntity().isActive()) return new Text("Working !").color(Color.GREEN.dark(3)); - else if (getBaseMetaTileEntity().isAllowedToWork()) - return new Text("Enabled").color(Color.GREEN.dark(3)); - else if (getBaseMetaTileEntity().wasShutdown()) - return new Text("Shutdown (CRITICAL)").color(Color.RED.dark(3)); - else return new Text("Disabled").color(Color.RED.dark(3)); - }).dynamicTooltip(() -> flowersGUI) - .setUpdateTooltipEveryTick(true)) - .setEnabled(isFixed)); - - screenElements - .widget( - new TextWidget(GT_Utility.trans("132", "Pipe is loose.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mWrench)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mWrench, val -> mWrench = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("133", "Screws are loose.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mScrewdriver)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mScrewdriver, val -> mScrewdriver = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("134", "Something is stuck.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mSoftHammer)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mSoftHammer, val -> mSoftHammer = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("135", "Platings are dented.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mHardHammer)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mHardHammer, val -> mHardHammer = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("136", "Circuitry burned out.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mSolderingTool)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mSolderingTool, val -> mSolderingTool = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("137", "That doesn't belong there.")) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mCrowbar)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mCrowbar, val -> mCrowbar = val)); - screenElements - .widget( - new TextWidget(GT_Utility.trans("138", "Incomplete Structure.")).setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> !mMachine)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> mMachine, val -> mMachine = val)); + + screenElements.widget(new FakeSyncWidget.IntegerSyncer(() -> mSecondaryMode, b -> mSecondaryMode = b)); + screenElements.widget(new FakeSyncWidget<>(() -> { + HashMap<ItemStack, Double> ret = new HashMap<>(); + HashMap<ItemID, Double> dropProgress = new HashMap<>(); + + for (Map.Entry<ItemID, Double> drop : this.dropProgress.entrySet()) { + dropProgress.merge(drop.getKey(), drop.getValue(), Double::sum); + } + + for (Map.Entry<ItemID, Double> drop : dropProgress.entrySet()) { + ret.put(BeeSimulator.dropstacks.get(drop.getKey()), drop.getValue()); + } + return ret; + }, h -> GUIDropProgress = h, (buffer, h) -> { + buffer.writeVarIntToBuffer(h.size()); + for (Map.Entry<ItemStack, Double> itemStackDoubleEntry : h.entrySet()) { + try { + buffer.writeItemStackToBuffer(itemStackDoubleEntry.getKey()); + buffer.writeDouble(itemStackDoubleEntry.getValue()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }, buffer -> { + int len = buffer.readVarIntFromBuffer(); + HashMap<ItemStack, Double> ret = new HashMap<>(len); + for (int i = 0; i < len; i++) { + try { + ret.put(buffer.readItemStackFromBuffer(), buffer.readDouble()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return ret; + })); + super.drawTexts(screenElements, inventorySlot); } + final HashMap<ItemID, Double> dropProgress = new HashMap<>(); + private static class BeeSimulator { final ItemStack queenStack; @@ -1280,20 +1046,27 @@ public class GT_MetaTileEntity_MegaIndustrialApiary return tag; } - final HashMap<BeeDrop, Double> dropProgress = new HashMap<>(); - - public List<ItemStack> getDrops(final double timePassed) { - drops.forEach(d -> dropProgress.merge(d, d.getAmount(timePassed / 550d), Double::sum)); - specialDrops.forEach(d -> dropProgress.merge(d, d.getAmount(timePassed / 550d), Double::sum)); + static final Map<ItemID, ItemStack> dropstacks = new HashMap<>(); + + public List<ItemStack> getDrops(final GT_MetaTileEntity_MegaIndustrialApiary MTE, final double timePassed) { + drops.forEach(d -> { + MTE.dropProgress.merge(d.id, d.getAmount(timePassed / 550d), Double::sum); + if (!dropstacks.containsKey(d.id)) dropstacks.put(d.id, d.stack); + }); + specialDrops.forEach(d -> { + MTE.dropProgress.merge(d.id, d.getAmount(timePassed / 550d), Double::sum); + if (!dropstacks.containsKey(d.id)) dropstacks.put(d.id, d.stack); + }); List<ItemStack> currentDrops = new ArrayList<>(); - dropProgress.entrySet() + MTE.dropProgress.entrySet() .forEach(e -> { double v = e.getValue(); while (v > 1.f) { int size = Math.min((int) v, 64); - currentDrops.add( - e.getKey() - .get(size)); + ItemStack stack = dropstacks.get(e.getKey()) + .copy(); + stack.stackSize = size; + currentDrops.add(stack); v -= size; e.setValue(v); } @@ -1318,7 +1091,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary private static final float MAX_PRODUCTION_MODIFIER_FROM_UPGRADES = 17.19926784f; // 4*1.2^8 final ItemStack stack; double amount; - final GT_Utility.ItemId id; + final ItemID id; final float chance; final float beeSpeed; @@ -1329,7 +1102,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary this.chance = chance; this.beeSpeed = beeSpeed; this.t = t; - id = GT_Utility.ItemId.createNoCopy(stack); + id = ItemID.createNoCopy(this.stack); evaluate(); } @@ -1365,7 +1138,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary beeSpeed = tag.getFloat("beeSpeed"); t = tag.getFloat("t"); amount = tag.getDouble("amount"); - id = GT_Utility.ItemId.createNoCopy(stack); + id = ItemID.createNoCopy(stack); } public NBTTagCompound toNBTTagCompound() { |