From cbe7ec5082dcbf26dc0311da297b84fd259fe8ef Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sun, 24 Nov 2019 23:08:12 -0600 Subject: [PATCH] Corporea index no longer xrays the world, nor messes up keybindings in-inventory. Also clean up the code a bit" --- .../botania/api/corporea/CorporeaHelper.java | 18 -- .../ICorporeaAutoCompleteController.java | 23 --- .../handler/CorporeaAutoCompleteHandler.java | 178 ------------------ .../core/handler/CorporeaInputHandler.java | 2 +- .../client/core/proxy/ClientProxy.java | 2 - .../block/corporea/BlockCorporeaIndex.java | 48 +---- .../tile/corporea/TileCorporeaIndex.java | 15 +- 7 files changed, 4 insertions(+), 282 deletions(-) delete mode 100644 src/main/java/vazkii/botania/api/corporea/ICorporeaAutoCompleteController.java delete mode 100644 src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java diff --git a/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java b/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java index 77179b8f8..a7037c9ce 100644 --- a/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java +++ b/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java @@ -33,7 +33,6 @@ public final class CorporeaHelper { private static final List empty = ImmutableList.of(); private static final WeakHashMap, List> cachedNetworks = new WeakHashMap<>(); - private static final List autoCompleteControllers = new ArrayList<>(); private static final Pattern patternControlCode = Pattern.compile("(?i)\\u00A7[0-9A-FK-OR]"); @@ -277,23 +276,6 @@ public final class CorporeaHelper { return contain ? s1.contains(s2) : s1.equals(s2); } - /** - * Registers a ICorporeaAutoCompleteController - */ - public static void registerAutoCompleteController(ICorporeaAutoCompleteController controller) { - autoCompleteControllers.add(controller); - } - - /** - * Returns if the auto complete helper should run - */ - public static boolean shouldAutoComplete() { - for(ICorporeaAutoCompleteController controller : autoCompleteControllers) - if(controller.shouldAutoComplete()) - return true; - return false; - } - // Copy from StringUtils public static String stripControlCodes(String str) { return patternControlCode.matcher(str).replaceAll(""); diff --git a/src/main/java/vazkii/botania/api/corporea/ICorporeaAutoCompleteController.java b/src/main/java/vazkii/botania/api/corporea/ICorporeaAutoCompleteController.java deleted file mode 100644 index b528020d8..000000000 --- a/src/main/java/vazkii/botania/api/corporea/ICorporeaAutoCompleteController.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * This class was created by . It's distributed as - * part of the Botania Mod. Get the Source Code in github: - * https://github.com/Vazkii/Botania - * - * Botania is Open Source and distributed under the - * Botania License: http://botaniamod.net/license.php - * - * File Created @ [June 8, 2015, 1:04:05 PM (GMT)] - */ -package vazkii.botania.api.corporea; - -/** - * An interface for systems which may control if the item auto complete system should be active - */ -public interface ICorporeaAutoCompleteController { - - /** - * Return true if auto completion should be enabled. - */ - public boolean shouldAutoComplete(); - -} diff --git a/src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java b/src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java deleted file mode 100644 index 0d47ff2c6..000000000 --- a/src/main/java/vazkii/botania/client/core/handler/CorporeaAutoCompleteHandler.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * This class was created by . It's distributed as - * part of the Botania Mod. Get the Source Code in github: - * https://github.com/Vazkii/Botania - * - * Botania is Open Source and distributed under the - * Botania License: http://botaniamod.net/license.php - * - * File Created @ [June 8, 2015, 12:55:20 AM (GMT)] - */ -package vazkii.botania.client.core.handler; - -import com.google.common.collect.ImmutableList; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.text.StringTextComponent; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.registries.ForgeRegistries; -import org.lwjgl.glfw.GLFW; -import vazkii.botania.api.corporea.CorporeaHelper; - -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -public class CorporeaAutoCompleteHandler { - - private boolean isAutoCompleted = false; - private String originalString = ""; - private List completions = new ArrayList<>(); - private int position; - - static final TreeSet itemNames = new TreeSet<>(String::compareToIgnoreCase); - - private boolean tabLastTick = false; - - public static void updateItemList() { - itemNames.clear(); - NonNullList curList = NonNullList.create(); - - for (Item item : ForgeRegistries.ITEMS) { - if(item != null && item.getGroup() != null) { - curList.clear(); - try { - item.fillItemGroup(ItemGroup.SEARCH, curList); - for(ItemStack stack : curList) - itemNames.add(CorporeaHelper.stripControlCodes(stack.getDisplayName().getString().trim())); - } - catch (Exception e) {} - } - } - } - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - if(event.phase != TickEvent.Phase.END) - return; - Screen screen = Minecraft.getInstance().currentScreen; - if(!(screen instanceof ChatScreen)) { - isAutoCompleted = false; - return; - } - ChatScreen chat = (ChatScreen) screen; - if(isAutoCompleted) { - boolean valid = false;//ReflectionHelper.getPrivateValue(GuiChat.class, chat, LibObfuscation.COMPLETE_FLAG); - if(!valid) - isAutoCompleted = false; - } - if(GLFW.glfwGetKey(Minecraft.getInstance().mainWindow.getHandle(), GLFW.GLFW_KEY_TAB) == GLFW.GLFW_PRESS) { - if(tabLastTick) - return; - tabLastTick = true; - } else { - tabLastTick = false; - return; - } - - if(!CorporeaHelper.shouldAutoComplete()) - return; - - if(!isAutoCompleted) - buildAutoCompletes(chat.inputField, chat); - if(isAutoCompleted && !completions.isEmpty()) - advanceAutoComplete(chat.inputField, chat); - } - - private void advanceAutoComplete(TextFieldWidget inputField, ChatScreen chat) { - position++; - if(position >= completions.size()) - position -= completions.size(); - CompletionData data = completions.get(position); - String str = originalString.substring(0, originalString.length() - data.prefixLength) + data.string; - inputField.setText(str); - } - - private void buildAutoCompletes(TextFieldWidget inputField, ChatScreen chat) { - String leftOfCursor; - if(inputField.getCursorPosition() == 0) - leftOfCursor = ""; - else - leftOfCursor = inputField.getText().substring(0, inputField.getCursorPosition()); - if(leftOfCursor.length() == 0 || leftOfCursor.charAt(0) == '/') - return; - completions = getNames(leftOfCursor); - if(completions.isEmpty()) - return; - position = -1; - //ReflectionHelper.setPrivateValue(GuiChat.class, chat, true, LibObfuscation.COMPLETE_FLAG); - StringBuilder stringbuilder = new StringBuilder(); - CompletionData data; - for(Iterator iterator = completions.iterator(); iterator.hasNext(); stringbuilder.append(data.string)) { - data = iterator.next(); - if(stringbuilder.length() > 0) - stringbuilder.append(", "); - } - - Minecraft.getInstance().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new StringTextComponent(stringbuilder.toString()), 1); - isAutoCompleted = true; - originalString = inputField.getText(); - } - - private List getNames(String prefix) { - String s = prefix.trim(); - if(s.isEmpty()) - return ImmutableList.of(); - - TreeSet result = new TreeSet<>(); - String[] words = s.split(" "); - int i = words.length - 1; - String curPrefix = words[i]; - while(i >= 0) { - result.addAll(getNamesStartingWith(curPrefix.toLowerCase())); - i--; - if(i >= 0) - curPrefix = words[i] + " " + curPrefix; - } - return new ArrayList<>(result); - } - - private List getNamesStartingWith(String prefix) { - ArrayList result = new ArrayList<>(); - int length = prefix.length(); - SortedSet after = itemNames.tailSet(prefix); - for(String str : after) { - if(str.toLowerCase().startsWith(prefix)) - result.add(new CompletionData(str, length)); - else return result; - } - return result; - } - - private static class CompletionData implements Comparable { - - private final String string; - private final int prefixLength; - - public CompletionData(String string, int prefixLength) { - this.string = string; - this.prefixLength = prefixLength; - } - - @Override - public int compareTo(@Nonnull CompletionData arg0) { - return string.compareTo(arg0.string); - } - } - -} diff --git a/src/main/java/vazkii/botania/client/core/handler/CorporeaInputHandler.java b/src/main/java/vazkii/botania/client/core/handler/CorporeaInputHandler.java index 766163763..12b20e32f 100644 --- a/src/main/java/vazkii/botania/client/core/handler/CorporeaInputHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/CorporeaInputHandler.java @@ -40,7 +40,7 @@ public class CorporeaInputHandler { public static void buttonPressed(GuiScreenEvent.KeyboardKeyPressedEvent.Pre event) { Minecraft mc = Minecraft.getInstance(); if(mc.world == null || !supportedGuiFilter.test(mc.currentScreen) - || ClientProxy.CORPOREA_REQUEST.isActiveAndMatches(InputMappings.getInputByCode(event.getKeyCode(), event.getScanCode())) + || !ClientProxy.CORPOREA_REQUEST.isActiveAndMatches(InputMappings.getInputByCode(event.getKeyCode(), event.getScanCode())) || TileCorporeaIndex.InputHandler.getNearbyIndexes(mc.player).isEmpty()) return; diff --git a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java index e0d82d5cb..2063725d4 100644 --- a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java @@ -36,7 +36,6 @@ import vazkii.botania.client.core.handler.BoundTileRenderer; import vazkii.botania.client.core.handler.ClientTickHandler; import vazkii.botania.client.core.handler.ColorHandler; import vazkii.botania.client.core.handler.ContributorFancinessHandler; -import vazkii.botania.client.core.handler.CorporeaAutoCompleteHandler; import vazkii.botania.client.core.handler.LayerTerraHelmet; import vazkii.botania.client.core.handler.MiscellaneousIcons; import vazkii.botania.client.core.handler.PersistentVariableHelper; @@ -116,7 +115,6 @@ public class ClientProxy implements IProxy { initAuxiliaryRender(); ColorHandler.init(); }); - CorporeaAutoCompleteHandler.updateItemList(); } private void initAuxiliaryRender() { diff --git a/src/main/java/vazkii/botania/common/block/corporea/BlockCorporeaIndex.java b/src/main/java/vazkii/botania/common/block/corporea/BlockCorporeaIndex.java index 0716c7855..95512aa9e 100644 --- a/src/main/java/vazkii/botania/common/block/corporea/BlockCorporeaIndex.java +++ b/src/main/java/vazkii/botania/common/block/corporea/BlockCorporeaIndex.java @@ -13,25 +13,13 @@ package vazkii.botania.common.block.corporea; import net.minecraft.block.Block; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; -import net.minecraft.client.particle.DiggingParticle; -import net.minecraft.entity.LivingEntity; -import net.minecraft.particles.BlockParticleData; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.world.IBlockReader; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.block.tile.corporea.TileCorporeaBase; import vazkii.botania.common.block.tile.corporea.TileCorporeaIndex; import javax.annotation.Nonnull; public class BlockCorporeaIndex extends BlockCorporeaBase { - public BlockCorporeaIndex(Block.Properties builder) { super(builder); } @@ -49,39 +37,7 @@ public class BlockCorporeaIndex extends BlockCorporeaBase { } @Override - public boolean addLandingEffects(BlockState state, ServerWorld world, BlockPos blockPosition, BlockState iblockstate, LivingEntity entity, int numberOfParticles ) - { - float f = MathHelper.ceil(entity.fallDistance - 3.0F); - double d0 = Math.min(0.2F + f / 15.0F, 10.0F); - if (d0 > 2.5D) { - d0 = 2.5D; - } - int i = (int)(150.0D * d0); - world.spawnParticle(new BlockParticleData(ParticleTypes.BLOCK, ModBlocks.elementiumBlock.getDefaultState()), entity.posX, entity.posY, entity.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D); - return true; + public boolean isSolid(BlockState state) { + return false; } - - @Override - @OnlyIn(Dist.CLIENT) - public boolean addDestroyEffects(BlockState state, World world, BlockPos pos, net.minecraft.client.particle.ParticleManager effectRenderer) - { - if (world.getBlockState(pos).getBlock() == this) { - int i = 4; - DiggingParticle.Factory factory = new DiggingParticle.Factory(); - for (int j = 0; j < i; ++j) { - for (int k = 0; k < i; ++k) { - for (int l = 0; l < i; ++l) { - double d0 = pos.getX() + (j + 0.5D) / i; - double d1 = pos.getY() + (k + 0.5D) / i; - double d2 = pos.getZ() + (l + 0.5D) / i; - effectRenderer.addEffect(factory.makeParticle(new BlockParticleData(ParticleTypes.BLOCK, ModBlocks.elementiumBlock.getDefaultState()), world, d0, d1, d2, d0 - pos.getX() - 0.5D, d1 - pos.getY() - 0.5D, d2 - pos.getZ() - 0.5D)); - } - } - } - return true; - } else { - return false; - } - } - } diff --git a/src/main/java/vazkii/botania/common/block/tile/corporea/TileCorporeaIndex.java b/src/main/java/vazkii/botania/common/block/tile/corporea/TileCorporeaIndex.java index 6c163df46..95d11fd28 100644 --- a/src/main/java/vazkii/botania/common/block/tile/corporea/TileCorporeaIndex.java +++ b/src/main/java/vazkii/botania/common/block/tile/corporea/TileCorporeaIndex.java @@ -30,7 +30,6 @@ import net.minecraftforge.registries.ObjectHolder; import org.apache.commons.lang3.text.WordUtils; import vazkii.botania.api.corporea.CorporeaHelper; import vazkii.botania.api.corporea.CorporeaIndexRequestEvent; -import vazkii.botania.api.corporea.ICorporeaAutoCompleteController; import vazkii.botania.api.corporea.ICorporeaRequestor; import vazkii.botania.api.corporea.ICorporeaSpark; import vazkii.botania.common.advancements.CorporeaRequestTrigger; @@ -258,12 +257,7 @@ public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequ set.remove(index); } - public static final class InputHandler implements ICorporeaAutoCompleteController { - - public InputHandler() { - CorporeaHelper.registerAutoCompleteController(this); - } - + public static final class InputHandler { @SubscribeEvent(priority = EventPriority.HIGHEST) public void onChatMessage(ServerChatEvent event) { List nearbyIndexes = getNearbyIndexes(event.getPlayer()); @@ -309,13 +303,6 @@ public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequ .stream().filter(i -> isInRangeOfIndex(player, i)) .collect(Collectors.toList()); } - - @Override - @OnlyIn(Dist.CLIENT) - public boolean shouldAutoComplete() { - return !getNearbyIndexes(Minecraft.getInstance().player).isEmpty(); - } - } public static interface IRegexStacker {