diff options
Diffstat (limited to 'src/main')
11 files changed, 247 insertions, 88 deletions
diff --git a/src/main/java/kubatech/api/helpers/ReflectionHelper.java b/src/main/java/kubatech/api/helpers/ReflectionHelper.java index 404d1de5f9..19b8ecd026 100644 --- a/src/main/java/kubatech/api/helpers/ReflectionHelper.java +++ b/src/main/java/kubatech/api/helpers/ReflectionHelper.java @@ -18,8 +18,8 @@ public class ReflectionHelper { private static class _FieldsMethods { - HashMap<String, Field> fields = new HashMap<>(); - HashMap<String, Method> methods = new HashMap<>(); + final HashMap<String, Field> fields = new HashMap<>(); + final HashMap<String, Method> methods = new HashMap<>(); } private static final HashMap<String, _FieldsMethods> classes = new HashMap<>(); @@ -35,7 +35,7 @@ public class ReflectionHelper { if (f == null) return defaultvalue; return (T) f.get(obj); } - boolean exceptionDetected = false; + boolean exceptionDetected; Field f = null; do { exceptionDetected = false; @@ -66,7 +66,7 @@ public class ReflectionHelper { f.set(obj, value); return true; } - boolean exceptionDetected = false; + boolean exceptionDetected; Field f = null; do { exceptionDetected = false; @@ -110,7 +110,7 @@ public class ReflectionHelper { if (m == null) return defaultValue; return (T) m.invoke(obj, args); } - boolean exceptionDetected = false; + boolean exceptionDetected; Method m = null; do { exceptionDetected = false; diff --git a/src/main/java/kubatech/api/implementations/KubaTechGTMultiBlockBase.java b/src/main/java/kubatech/api/implementations/KubaTechGTMultiBlockBase.java index 0b31c27011..732dbba88a 100644 --- a/src/main/java/kubatech/api/implementations/KubaTechGTMultiBlockBase.java +++ b/src/main/java/kubatech/api/implementations/KubaTechGTMultiBlockBase.java @@ -8,17 +8,62 @@ import java.util.Arrays; import java.util.function.Function; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fluids.FluidStack; import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; +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.UIBuilder; +import com.gtnewhorizons.modularui.common.builder.UIInfo; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.metatileentity.BaseMetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ExtendedPowerMultiBlockBase; public abstract class KubaTechGTMultiBlockBase<T extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<T>> extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<T> { + @SuppressWarnings("unchecked") + protected static <K extends KubaTechGTMultiBlockBase<?>> UIInfo<?, ?> createKTMetaTileEntityUI( + KTContainerConstructor<K> containerConstructor) { + return UIBuilder.of().container((player, world, x, y, z) -> { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof BaseMetaTileEntity) { + IMetaTileEntity mte = ((BaseMetaTileEntity) te).getMetaTileEntity(); + if (!(mte instanceof KubaTechGTMultiBlockBase)) return null; + final UIBuildContext buildContext = new UIBuildContext(player); + final ModularWindow window = ((ITileWithModularUI) te).createWindow(buildContext); + return containerConstructor.of(new ModularUIContext(buildContext, te::markDirty), window, (K) mte); + } + return null; + }).gui(((player, world, x, y, z) -> { + if (!world.isRemote) return null; + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof BaseMetaTileEntity) { + IMetaTileEntity mte = ((BaseMetaTileEntity) te).getMetaTileEntity(); + if (!(mte instanceof KubaTechGTMultiBlockBase)) return null; + final UIBuildContext buildContext = new UIBuildContext(player); + final ModularWindow window = ((ITileWithModularUI) te).createWindow(buildContext); + return new ModularGui( + containerConstructor.of(new ModularUIContext(buildContext, null), window, (K) mte)); + } + return null; + })).build(); + } + + @FunctionalInterface + protected interface KTContainerConstructor<T extends KubaTechGTMultiBlockBase<?>> { + + ModularUIContainer of(ModularUIContext context, ModularWindow mainWindow, T multiBlock); + } + protected KubaTechGTMultiBlockBase(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -30,7 +75,7 @@ public abstract class KubaTechGTMultiBlockBase<T extends GT_MetaTileEntity_Exten /** * Enables infinite overclocking (will give more outputs with more energy past 1 tick) Currently doesn't support * recipe inputs - * + * * @return If this supports infinite overclock */ protected boolean isOverclockingInfinite() { diff --git a/src/main/java/kubatech/config/OverridesConfig.java b/src/main/java/kubatech/config/OverridesConfig.java index 365638727d..3c7e93c92f 100644 --- a/src/main/java/kubatech/config/OverridesConfig.java +++ b/src/main/java/kubatech/config/OverridesConfig.java @@ -96,8 +96,8 @@ public class OverridesConfig { public static class MobOverride { public boolean removeAll = false; - public List<MobDrop> additions = new ArrayList<>(); - public List<MobDropSimplified> removals = new ArrayList<>(); + public final List<MobDrop> additions = new ArrayList<>(); + public final List<MobDropSimplified> removals = new ArrayList<>(); private static final ByteBuf BufHelper = Unpooled.buffer(); diff --git a/src/main/java/kubatech/kubatech.java b/src/main/java/kubatech/kubatech.java index b12693dec4..a459116d83 100644 --- a/src/main/java/kubatech/kubatech.java +++ b/src/main/java/kubatech/kubatech.java @@ -75,7 +75,7 @@ public class kubatech { return Tags.MODNAME; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void displayAllReleventItems(List p_78018_1_) { super.displayAllReleventItems(p_78018_1_); diff --git a/src/main/java/kubatech/loaders/MobRecipeLoader.java b/src/main/java/kubatech/loaders/MobRecipeLoader.java index f530b8921b..a63f3dad13 100644 --- a/src/main/java/kubatech/loaders/MobRecipeLoader.java +++ b/src/main/java/kubatech/loaders/MobRecipeLoader.java @@ -172,6 +172,7 @@ public class MobRecipeLoader { dropinstance instance = infernaldrops .add(new dropinstance(stack.copy(), infernaldrops), chance / elitelist.size()); instance.isEnchatmentRandomized = true; + // noinspection ConstantConditions instance.enchantmentLevel = stack.getItem().getItemEnchantability(); } ArrayList<ItemStack> ultralist = InfernalHelper.getDropIdListUltra(); @@ -180,6 +181,7 @@ public class MobRecipeLoader { dropinstance instance = infernaldrops .add(new dropinstance(stack.copy(), infernaldrops), chance / ultralist.size()); instance.isEnchatmentRandomized = true; + // noinspection ConstantConditions instance.enchantmentLevel = stack.getItem().getItemEnchantability(); } ArrayList<ItemStack> infernallist = InfernalHelper.getDropIdListInfernal(); @@ -188,6 +190,7 @@ public class MobRecipeLoader { dropinstance instance = infernaldrops .add(new dropinstance(stack.copy(), infernaldrops), chance / infernallist.size()); instance.isEnchatmentRandomized = true; + // noinspection ConstantConditions instance.enchantmentLevel = stack.getItem().getItemEnchantability(); } } @@ -271,12 +274,13 @@ public class MobRecipeLoader { } else if (p == 2) { infernalstacks = InfernalHelper.getDropIdListUltra(); mods = InfernalHelper.getMinUltraModifiers(); - } else if (p == 3) { + } else { infernalstacks = InfernalHelper.getDropIdListInfernal(); mods = InfernalHelper.getMinInfernoModifiers(); } if (infernalstacks != null) { ItemStack infernalstack = infernalstacks.get(rnd.nextInt(infernalstacks.size())).copy(); + // noinspection ConstantConditions EnchantmentHelper .addRandomEnchantment(rnd, infernalstack, infernalstack.getItem().getItemEnchantability()); stacks.add(infernalstack); diff --git a/src/main/java/kubatech/loaders/TCLoader.java b/src/main/java/kubatech/loaders/TCLoader.java index fb803e0198..a4141d4ba5 100644 --- a/src/main/java/kubatech/loaders/TCLoader.java +++ b/src/main/java/kubatech/loaders/TCLoader.java @@ -36,8 +36,6 @@ import cpw.mods.fml.common.registry.GameRegistry; public class TCLoader { - private static boolean lateLoaded = false; - public static void load() {} public static void register() { diff --git a/src/main/java/kubatech/loaders/block/KubaBlock.java b/src/main/java/kubatech/loaders/block/KubaBlock.java index 831757f332..92481c3f8a 100644 --- a/src/main/java/kubatech/loaders/block/KubaBlock.java +++ b/src/main/java/kubatech/loaders/block/KubaBlock.java @@ -47,8 +47,8 @@ public class KubaBlock extends Block { .of().container((player, world, x, y, z) -> { TileEntity te = world.getTileEntity(x, y, z); if (te instanceof ITileWithModularUI) { - UIBuildContext buildContext = new UIBuildContext(player); - ModularWindow window = ((ITileWithModularUI) te).createWindow(buildContext); + final UIBuildContext buildContext = new UIBuildContext(player); + final ModularWindow window = ((ITileWithModularUI) te).createWindow(buildContext); return containerConstructor .createUIContainer(new ModularUIContext(buildContext, te::markDirty), window); } @@ -57,8 +57,8 @@ public class KubaBlock extends Block { if (!world.isRemote) return null; TileEntity te = world.getTileEntity(x, y, z); if (te instanceof ITileWithModularUI) { - UIBuildContext buildContext = new UIBuildContext(player); - ModularWindow window = ((ITileWithModularUI) te).createWindow(buildContext); + final UIBuildContext buildContext = new UIBuildContext(player); + final ModularWindow window = ((ITileWithModularUI) te).createWindow(buildContext); return new ModularGui( containerConstructor.createUIContainer(new ModularUIContext(buildContext, null), window)); } @@ -100,7 +100,7 @@ public class KubaBlock extends Block { return getBlock(meta) instanceof IProxyTileEntityProvider; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_) { for (int i = 0; i < blocks.size(); i++) p_149666_3_.add(new ItemStack(p_149666_1_, 1, i)); diff --git a/src/main/java/kubatech/loaders/block/KubaItemBlock.java b/src/main/java/kubatech/loaders/block/KubaItemBlock.java index 64f3124314..8d497a6a0f 100644 --- a/src/main/java/kubatech/loaders/block/KubaItemBlock.java +++ b/src/main/java/kubatech/loaders/block/KubaItemBlock.java @@ -12,8 +12,6 @@ package kubatech.loaders.block; import java.util.List; -import kubatech.kubatech; - import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; @@ -42,7 +40,7 @@ public class KubaItemBlock extends ItemBlock { return KubaBlock.blocks.get(p_77653_1_.getItemDamage()).getDisplayName(p_77653_1_); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override 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_); diff --git a/src/main/java/kubatech/loaders/item/KubaItems.java b/src/main/java/kubatech/loaders/item/KubaItems.java index 55d835cb87..c01396ca96 100644 --- a/src/main/java/kubatech/loaders/item/KubaItems.java +++ b/src/main/java/kubatech/loaders/item/KubaItems.java @@ -92,7 +92,7 @@ public class KubaItems extends Item { return p_77647_1_; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { getItem(p_77624_1_).addInformation(p_77624_1_, p_77624_2_, (List<String>) p_77624_3_, p_77624_4_); @@ -120,7 +120,7 @@ public class KubaItems extends Item { return getItem(damage).getIcon(); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_) { for (int i = 0; i < items.size(); i++) p_150895_3_.add(new ItemStack(p_150895_1_, 1, i)); diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java index d74958b76b..f7e2fee904 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java @@ -235,7 +235,7 @@ public class GT_MetaTileEntity_ExtremeExterminationChamber .addInfo("The mobs will start to buffer and die very slowly by a ritual") .addInfo("You can disable mob animation with a soldering iron").addInfo(StructureHologram) .addSeparator().beginStructureBlock(5, 7, 5, true).addController("Front Bottom Center") - .addCasingInfo("Solid Steel Machine Casing", 10) + .addCasingInfoMin("Solid Steel Machine Casing", 10, false) .addOtherStructurePart("Borosilicate Glass", "All walls without corners") .addStructureInfo("The glass tier limits the Energy Input tier") .addOtherStructurePart("Steel Frame Box", "All vertical corners (except top and bottom)") @@ -501,6 +501,7 @@ public class GT_MetaTileEntity_ExtremeExterminationChamber EECPlayer.currentWeapon = lootingHolder; Item lootingHolderItem = lootingHolder.getItem(); for (int i = 0; i < times + 1; i++) { + // noinspection ConstantConditions if (!lootingHolderItem.hitEntity(lootingHolder, recipe.entity, EECPlayer)) break; if (lootingHolder.stackSize == 0) { // noinspection ConstantConditions 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 680558d25c..73959d6e9b 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 @@ -14,12 +14,13 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static forestry.api.apiculture.BeeManager.beeRoot; import static gregtech.api.enums.GT_HatchElement.*; import static gregtech.api.enums.Textures.BlockIcons.*; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_GLOW; import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; import static kubatech.api.Variables.*; import java.io.IOException; +import java.lang.ref.WeakReference; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -27,17 +28,15 @@ import kubatech.Tags; import kubatech.api.LoaderReference; import kubatech.api.helpers.GTHelper; import kubatech.api.implementations.KubaTechGTMultiBlockBase; -import kubatech.api.network.CustomTileEntityPacket; -import kubatech.api.tileentity.CustomTileEntityPacketHandler; import kubatech.client.effect.MegaApiaryBeesRenderer; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; @@ -55,8 +54,12 @@ import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.math.Color; import com.gtnewhorizons.modularui.api.math.Pos2d; +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.*; import cpw.mods.fml.relauncher.Side; @@ -79,8 +82,7 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; public class GT_MetaTileEntity_MegaIndustrialApiary - extends KubaTechGTMultiBlockBase<GT_MetaTileEntity_MegaIndustrialApiary> - implements CustomTileEntityPacketHandler, ISurvivalConstructable { + extends KubaTechGTMultiBlockBase<GT_MetaTileEntity_MegaIndustrialApiary> implements ISurvivalConstructable { private byte mGlassTier = 0; private int mCasing = 0; @@ -256,7 +258,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary .addInfo(" - Consumes 100 royal jelly per operation").addInfo(" - Base processing time: 1 minute") .addInfo(" - Uses 1 amp " + voltageFormatted(5)).addInfo(" - Can overclock") .addInfo(StructureHologram).addSeparator().beginStructureBlock(15, 17, 15, false) - .addController("Front Bottom Center").addCasingInfo("Bronze Plated Bricks", 190) + .addController("Front Bottom Center").addCasingInfoMin("Bronze Plated Bricks", 190, false) .addOtherStructurePart("Borosilicate Glass", "Look at the hologram") .addStructureInfo("The glass tier limits the Energy Input tier") .addOtherStructurePart("Flowers", "On dirt/grass", 2).addInputBus("Any casing", 1) @@ -340,18 +342,12 @@ public class GT_MetaTileEntity_MegaIndustrialApiary } } - private CustomTileEntityPacket packet = null; - @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); if (aBaseMetaTileEntity.isServerSide()) { // TODO: Look for proper fix if (mUpdate < 0) mUpdate = 600; - if (packet == null) packet = new CustomTileEntityPacket((TileEntity) aBaseMetaTileEntity, null); - packet.resetHelperData(); - packet.addData(mMaxSlots); - packet.sendToAllAround(20); } else { if (aBaseMetaTileEntity.isActive() && aTick % 100 == 0) { int[] abc = new int[] { 0, -2, 7 }; @@ -450,7 +446,6 @@ public class GT_MetaTileEntity_MegaIndustrialApiary this.mEfficiencyIncrease = 10000; this.mMaxProgresstime = 100; this.mOutputItems = stacks.toArray(new ItemStack[0]); - return true; } else { if (!depleteInput(PluginApiculture.items.royalJelly.getItemStack(64)) || !depleteInput(PluginApiculture.items.royalJelly.getItemStack(36))) { @@ -463,8 +458,8 @@ public class GT_MetaTileEntity_MegaIndustrialApiary this.mEfficiencyIncrease = 10000; this.mOutputItems = new ItemStack[] { this.mStorage.get(0).createIgnobleCopy() }; this.updateSlots(); - return true; } + return true; } } @@ -546,11 +541,6 @@ public class GT_MetaTileEntity_MegaIndustrialApiary } @Override - public void HandleCustomPacket(CustomTileEntityPacket customdata) { - mMaxSlots = customdata.getDataInt(); - } - - @Override public boolean useModularUI() { return true; } @@ -570,6 +560,65 @@ public class GT_MetaTileEntity_MegaIndustrialApiary builder.bindPlayerInventory(buildContext.getPlayer(), new Pos2d(7, 83), this.getGUITextureSet().getItemSlot()); } + private static final UIInfo<?, ?> MegaApiaryUI = createKTMetaTileEntityUI( + KT_ModulaUIContainer_MegaIndustrialApiary::new); + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + MegaApiaryUI.open( + aPlayer, + aBaseMetaTileEntity.getWorld(), + aBaseMetaTileEntity.getXCoord(), + aBaseMetaTileEntity.getYCoord(), + aBaseMetaTileEntity.getZCoord()); + return true; + } + + private static class KT_ModulaUIContainer_MegaIndustrialApiary extends ModularUIContainer { + + final WeakReference<GT_MetaTileEntity_MegaIndustrialApiary> parent; + + public KT_ModulaUIContainer_MegaIndustrialApiary(ModularUIContext context, ModularWindow mainWindow, + GT_MetaTileEntity_MegaIndustrialApiary mte) { + super(context, mainWindow); + parent = new WeakReference<>(mte); + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer aPlayer, int aSlotIndex) { + if (!(aPlayer instanceof EntityPlayerMP)) return super.transferStackInSlot(aPlayer, aSlotIndex); + final Slot s = getSlot(aSlotIndex); + if (s == null) return super.transferStackInSlot(aPlayer, aSlotIndex); + if (aSlotIndex >= 36) return super.transferStackInSlot(aPlayer, aSlotIndex); + final ItemStack aStack = s.getStack(); + if (aStack == null) return super.transferStackInSlot(aPlayer, aSlotIndex); + GT_MetaTileEntity_MegaIndustrialApiary mte = parent.get(); + if (mte == null) return super.transferStackInSlot(aPlayer, aSlotIndex); + if (mte.mStorage.size() >= mte.mMaxSlots) return super.transferStackInSlot(aPlayer, aSlotIndex); + if (beeRoot.getType(aStack) == EnumBeeType.QUEEN) { + if (mte.mMaxProgresstime > 0) { + GT_Utility.sendChatToPlayer(aPlayer, EnumChatFormatting.RED + "Can't insert while running !"); + return super.transferStackInSlot(aPlayer, aSlotIndex); + } + World w = mte.getBaseMetaTileEntity().getWorld(); + float t = (float) GTHelper.getVoltageTierD(mte); + BeeSimulator bs = new BeeSimulator(aStack, w, t); + if (bs.isValid) { + mte.mStorage.add(bs); + s.putStack(null); + detectAndSendChanges(); + mte.isCacheDirty = true; + return null; + } + } + return super.transferStackInSlot(aPlayer, aSlotIndex); + } + } + + private final List<ItemStack> drawables = new ArrayList<>(mMaxSlots); + + @SuppressWarnings("UnstableApiUsage") @Override public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { builder.widget( @@ -610,11 +659,51 @@ public class GT_MetaTileEntity_MegaIndustrialApiary .addTooltip("Configuration").setSize(18, 18)) .setPos(151, 4)); - final List<ItemStack> drawables = new ArrayList<>(mMaxSlots); - final int perRow = 7; + ChangeableWidget beesContainer = new ChangeableWidget(() -> createBeesContainerWidget(player)); - Scrollable beesContainer = new Scrollable().setVerticalScroll(); + AtomicInteger lastMaxSlots = 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.ListSyncer<>( + () -> mStorage.stream().map(s -> s.queenStack).collect(Collectors.toList()), + l -> { + drawables.clear(); + drawables.addAll(l); + }, + (buffer, i) -> { + try { + buffer.writeItemStackToBuffer(i); + } catch (IOException e) { + throw new RuntimeException(e); + } + }, + buffer -> { + try { + return buffer.readItemStackFromBuffer(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }), + builder)); + final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); + drawTexts(screenElements, null); + builder.widget(screenElements); + } + + private Widget createBeesContainerWidget(EntityPlayer player) { + Scrollable beesContainer = new Scrollable().setVerticalScroll(); + final int perRow = 7; if (mMaxSlots > 0) for (int i = 0, imax = ((mMaxSlots - 1) / perRow); i <= imax; i++) { DynamicPositionedRow row = new DynamicPositionedRow().setSynced(false); for (int j = 0, jmax = (i == imax ? (mMaxSlots - 1) % perRow : (perRow - 1)); j <= jmax; j++) { @@ -623,14 +712,62 @@ public class GT_MetaTileEntity_MegaIndustrialApiary final int ID = finalI + finalJ; row.widget(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/insert while running !"); + return; + } + if (beeRoot.getType(input) == EnumBeeType.QUEEN) { + World w = getBaseMetaTileEntity().getWorld(); + float t = (float) GTHelper.getVoltageTierD(this); + BeeSimulator bs = new BeeSimulator(input, w, t); + if (bs.isValid) { + if (mStorage.size() > ID) { + BeeSimulator removed = mStorage.remove(ID); + mStorage.add(ID, bs); + player.inventory.setItemStack(removed.queenStack); + + } else { + mStorage.add(bs); + player.inventory.setItemStack(null); + } + ((EntityPlayerMP) player).isChangingQuantityOnly = false; + ((EntityPlayerMP) player).updateHeldItem(); + + isCacheDirty = true; + } + } + return; + } + } + if (mStorage.size() <= ID) return; if (this.mMaxProgresstime > 0) { - GT_Utility.sendChatToPlayer(player, "Can't eject while running !"); + GT_Utility.sendChatToPlayer(player, EnumChatFormatting.RED + "Can't eject while running !"); return; } BeeSimulator removed = mStorage.remove(ID); - addOutput(removed.queenStack); 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; + } + } + + addOutput(removed.queenStack); GT_Utility.sendChatToPlayer(player, "Queen ejected !"); }).setBackground( () -> new IDrawable[] { getBaseMetaTileEntity().getGUITextureSet().getItemSlot(), @@ -640,41 +777,18 @@ public class GT_MetaTileEntity_MegaIndustrialApiary .dynamicTooltip(() -> { if (drawables.size() > ID) return Arrays.asList( drawables.get(ID).getDisplayName(), - EnumChatFormatting.GRAY + "Left click to eject"); - return Collections.emptyList(); + 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 + .singletonList(EnumChatFormatting.GRAY + "Click with queen in mouse to insert"); }).setSize(18, 18)); } - beesContainer.widget( - row.setPos(0, i * 18).setEnabled(widget -> widget.getPos().y < beesContainer.getVisibleHeight())); + beesContainer.widget(row.setPos(0, i * 18)); } - beesContainer.attachSyncer( - new FakeSyncWidget.ListSyncer<>( - () -> mStorage.stream().map(s -> s.queenStack).collect(Collectors.toList()), - l -> { - drawables.clear(); - drawables.addAll(l); - }, - (buffer, i) -> { - try { - buffer.writeItemStackToBuffer(i); - } catch (IOException e) { - throw new RuntimeException(e); - } - }, - buffer -> { - try { - return buffer.readItemStackFromBuffer(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }), - builder); - - builder.widget(beesContainer.setPos(10, 16).setSize(128, 60)); - - final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); - drawTexts(screenElements, null); - builder.widget(screenElements); + beesContainer.setPos(10, 16).setSize(128, 60); + return beesContainer; } protected ModularWindow createConfigurationWindow(final EntityPlayer player) { @@ -830,10 +944,8 @@ public class GT_MetaTileEntity_MegaIndustrialApiary private static class BeeSimulator { - ItemStack queenStack; + final ItemStack queenStack; boolean isValid; - // boolean isBreadingMode; - // boolean isInfinite; List<BeeDrop> drops = new ArrayList<>(); List<BeeDrop> specialDrops = new ArrayList<>(); float beeSpeed; @@ -905,7 +1017,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary return tag; } - HashMap<BeeDrop, Double> dropProgress = new HashMap<>(); + 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)); @@ -936,12 +1048,12 @@ public class GT_MetaTileEntity_MegaIndustrialApiary private static class BeeDrop { - ItemStack stack; + final ItemStack stack; double amount; - GT_Utility.ItemId id; + final GT_Utility.ItemId id; - float chance; - float beeSpeed; + final float chance; + final float beeSpeed; float t; public BeeDrop(ItemStack stack, float chance, float beeSpeed, float t) { @@ -999,4 +1111,5 @@ public class GT_MetaTileEntity_MegaIndustrialApiary } } } + } |