mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 10:55:17 +00:00
Corporea index no longer xrays the world, nor messes up keybindings in-inventory. Also clean up the code a bit"
This commit is contained in:
1 parent
f433ee8858
commit
cbe7ec5082
7 files changed
+4
-282
No files matched your search
@@ -33,7 +33,6 @@ public final class CorporeaHelper {
|
||||
|
||||
private static final List<InvWithLocation> empty = ImmutableList.of();
|
||||
private static final WeakHashMap<List<ICorporeaSpark>, List<InvWithLocation>> cachedNetworks = new WeakHashMap<>();
|
||||
private static final List<ICorporeaAutoCompleteController> 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("");
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* This class was created by <SoundLogic>. 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();
|
||||
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/**
|
||||
* This class was created by <SoundLogic>. 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<CompletionData> completions = new ArrayList<>();
|
||||
private int position;
|
||||
|
||||
static final TreeSet<String> itemNames = new TreeSet<>(String::compareToIgnoreCase);
|
||||
|
||||
private boolean tabLastTick = false;
|
||||
|
||||
public static void updateItemList() {
|
||||
itemNames.clear();
|
||||
NonNullList<ItemStack> 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<CompletionData> 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<CompletionData> getNames(String prefix) {
|
||||
String s = prefix.trim();
|
||||
if(s.isEmpty())
|
||||
return ImmutableList.of();
|
||||
|
||||
TreeSet<CompletionData> 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<CompletionData> getNamesStartingWith(String prefix) {
|
||||
ArrayList<CompletionData> result = new ArrayList<>();
|
||||
int length = prefix.length();
|
||||
SortedSet<String> 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<CompletionData> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<TileCorporeaIndex> 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 {
|
||||
|
||||
Reference in new issue
Block a user