Skip to content

Commit

Permalink
Added /auswurf and fixed some bugs including a bug caused by LabyMod …
Browse files Browse the repository at this point in the history
…itself which caused wrong key press detection. As LabyMod won't fix this we had to solve the problem with a workaround.
  • Loading branch information
tmbRandy committed Jun 30, 2024
1 parent 7da0352 commit 41aded9
Show file tree
Hide file tree
Showing 33 changed files with 513 additions and 213 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Dieser Befehl ist das Gegenstück zu /pay * <betrag>. Wenn z.B. 100 Spieler auf
### Befehl /fahndung <name>
Du suchst einen Spieler, von dem du weißt, dass er online ist aber er hat seinen aktuellen CB nicht im /profil angegeben? Mit diesem Befehl wechselst du der Reihe nach alle CBs durch (beginnend mit den stark besuchten CBs). Sobald der Spieler auf einem CB gefunden wurde, wird die Fahndung beendet und du erhältst eine Ausgabe im Chat. Du willst eine Nachricht in deinem Status verbreiten? Kein Problem. Gib nur /fahndung ohne einen Namen ein und du wechselst alle CBs einmal durch.

### Befehl /auswurf
Mit /auswurf kannst du ein endloses Lager automatisch leeren. Die Kiste wird immer wieder geöffnet und alle Items aus dem Kisteninventar gedroppt. Dies kann nützlich sein, wenn du ein nicht komprimierbares Item aus einem endlosen Lager in ein neues endloses Lager umschichten willst. Deaktiviere hierzu die Einsaugfunktion des alten Lagers, aktiviere sie beim neuen Lager, gib den Befehl /auswurf ein und öffne das zu leerende, endlose Lager.

### Item Schutz
Das Addon verhindert die Abnutzung wertvoller Farmitems. So ist ein Zuschlagen mit einer Bonze- oder BIRTH Klinge, das Schießen mit dem BIRTH Bogen, sowie das Platzieren eines SoS nicht möglich. Diese Funktionen wurden ausreichend getestet und funktionieren grundsätzlich. Aus Prinzip können wir jedoch keinerlei Haftung für die Funktion übernehmen. Wir werden keine Items erstatten. Diese Funktion verhindert lediglich Mausklicks, die durch den Spieler selbst ausgeführt werden. Softwareseitige Klicks, wie z.B. durch einen Autoklicker würde das Addon nicht verhindern, sodass damit z.B. ein SoS gesetzt werden könnte.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "tmb.randy"
version = "1.3"
version = "1.4"

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

Expand Down
15 changes: 2 additions & 13 deletions core/src/main/java/tmb/randy/tmbgriefergames/core/Addon.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.labymod.api.models.addon.annotation.AddonMain;
import tmb.randy.tmbgriefergames.core.commands.AutocraftCommand;
import tmb.randy.tmbgriefergames.core.commands.DKsCommand;
import tmb.randy.tmbgriefergames.core.commands.EjectCommand;
import tmb.randy.tmbgriefergames.core.commands.PayAllCommand;
import tmb.randy.tmbgriefergames.core.commands.PlayerTracerCommand;
import tmb.randy.tmbgriefergames.core.config.Configuration;
Expand Down Expand Up @@ -36,6 +37,7 @@ protected void enable() {
this.registerCommand(new PayAllCommand());
this.registerCommand(new PlayerTracerCommand());
this.registerCommand(new AutocraftCommand());
this.registerCommand(new EjectCommand());

gameInfoWidget = new GameInfoWidget();

Expand Down Expand Up @@ -88,17 +90,4 @@ public static boolean isChatGuiOpen() {

return false;
}

public static boolean areKeysPressed(Key[] keys) {
if(isChatGuiOpen() || keys.length == 0)
return false;

for (Key key : keys) {
if(!key.isPressed() || key == Key.NONE) {
return false;
}
}

return true;
}
}
14 changes: 8 additions & 6 deletions core/src/main/java/tmb/randy/tmbgriefergames/core/IBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

@Referenceable
public interface IBridge {
public void startPlayerTracer(String name);
public void cbChanged();
public boolean isFlyCountdownActive();
public String getWidgetString();
public String getItemRemoverValue();
public void startNewAutocrafter();
void startPlayerTracer(String name);
void cbChanged();
boolean isFlyCountdownActive();
String getWidgetString();
String getItemRemoverValue();
void startNewAutocrafter();
boolean isCompActive();
void changeSlot(int slot);
void startAuswurf();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tmb.randy.tmbgriefergames.core.commands;

import net.labymod.api.client.chat.command.Command;
import tmb.randy.tmbgriefergames.core.Addon;

public class EjectCommand extends Command {

public EjectCommand() {
super("auswurf");
}

@Override
public boolean execute(String prefix, String[] arguments) {
if(!Addon.isGG())
return false;

Addon.getSharedInstance().getBridge().startAuswurf();

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public PayAllCommand() {
@Override
public boolean execute(String prefix, String[] arguments) {
if(!Addon.isGG())
return true;
return false;

if(arguments.length == 2) {
if((arguments[0].equals("**") || arguments[0].equals("/")) && Float.parseFloat(arguments[1]) >= 1F) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting;
import net.labymod.api.client.gui.screen.widget.widgets.input.dropdown.DropdownWidget.DropdownSetting;
import net.labymod.api.configuration.loader.Config;
import net.labymod.api.configuration.loader.annotation.ParentSwitch;
import net.labymod.api.configuration.loader.annotation.ShowSettingInParent;
import net.labymod.api.configuration.loader.property.ConfigProperty;
import tmb.randy.tmbgriefergames.core.enums.HopperFinalAction;
import tmb.randy.tmbgriefergames.core.enums.HopperItemStackSizeEnum;

public class HopperSubConfig extends Config {

@ParentSwitch
@ShowSettingInParent
@SwitchSetting
private final ConfigProperty<Boolean> enabled = new ConfigProperty<>(false);
@SwitchSetting
private final ConfigProperty<Boolean> filterItem = new ConfigProperty<>(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting;
import net.labymod.api.client.gui.screen.widget.widgets.input.color.ColorPickerWidget.ColorPickerSetting;
import net.labymod.api.configuration.loader.Config;
import net.labymod.api.configuration.loader.annotation.ParentSwitch;
import net.labymod.api.configuration.loader.annotation.ShowSettingInParent;
import net.labymod.api.configuration.loader.property.ConfigProperty;

public class NatureSubConfig extends Config {

@ParentSwitch
@ShowSettingInParent
@SwitchSetting
private final ConfigProperty<Boolean> showBorders = new ConfigProperty<>(false);

@SliderSetting(min = 1, max = 10, steps = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class NearbyWidget extends TextHudWidget<TextHudWidgetConfig> {

private final List<String> blacklist = Arrays.asList(
private static final List<String> blacklist = Arrays.asList(
"Adventurer",
"Admin-Shop",
"Statistik",
Expand All @@ -28,7 +28,9 @@ public class NearbyWidget extends TextHudWidget<TextHudWidgetConfig> {
"Skyblock Museum",
"Impressum",
"Datenschutz",
"Jobs"
"Jobs",
"Block des Tages",
"GS-Bewertungen"
);

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
"recipeSaved": "Rezept gespeichert",
"active": "Endlosmodus §a§lAKTIV",
"inactive": "Endlosmodus §c§lDEAKTIVIERT"
},
"eject": {
"enabled": "Auswurf §a§lAKTIVIERT. §fÖffne ein unendliches Lager!",
"disabled": "Auswurf §c§lDEAKTIVIERT"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
"recipeSaved": "Recipe saved",
"active": "Endless mode §a§ACTIVE",
"inactive": "Endless mode §c§INACTIVE"
},
"eject": {
"enabled": "Eject §a§lACTIVE. §fOpen an endless chest!",
"disabled": "Eject §c§lINACTIVE"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package tmb.randy.tmbgriefergames.v1_12_2.util;

import net.labymod.api.client.gui.screen.key.Key;
import net.labymod.api.event.client.input.KeyEvent;
import net.labymod.api.event.client.input.KeyEvent.State;
import net.labymod.api.event.client.lifecycle.GameTickEvent;
import net.labymod.api.util.I18n;
import net.minecraft.block.BlockChest;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.RayTraceResult.Type;
import tmb.randy.tmbgriefergames.core.Addon;
import tmb.randy.tmbgriefergames.core.enums.QueueType;
import tmb.randy.tmbgriefergames.v1_12_2.util.click.ClickManager;

public class Auswurf {
private boolean active;
private BlockPos chestPos;

public void onTickEvent(GameTickEvent event) {
if(active && Minecraft.getMinecraft().player != null && Minecraft.getMinecraft().world != null) {
if(Minecraft.getMinecraft().player.openContainer instanceof ContainerChest chest) {
IInventory inv = chest.getLowerChestInventory();
if(inv.getName().startsWith("§0Lager: ")) {
if(chestPos == null) {
chestPos = getChestPos();
} else {
if(ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM)) {
for (int i = 0; i < 25; i++) {
Slot slot = chest.getSlot(i);
if(slot.getHasStack()) {
ClickManager.getSharedInstance().dropClick(i);
}
}

if(ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM)) {
Minecraft.getMinecraft().displayGuiScreen(null);
Minecraft.getMinecraft().player.closeScreen();
RayTraceResult rayTraceResult = Minecraft.getMinecraft().objectMouseOver;
if(rayTraceResult.typeOfHit == Type.BLOCK && rayTraceResult.getBlockPos().equals(chestPos)) {
Minecraft.getMinecraft().playerController.processRightClickBlock(Minecraft.getMinecraft().player, Minecraft.getMinecraft().world, chestPos, rayTraceResult.sideHit, rayTraceResult.hitVec, EnumHand.MAIN_HAND);
}

}
}
}
}
}
}
}

public void onKeyEvent(KeyEvent event) {
if(event.state() == State.PRESS) {
if (active && event.key() == Key.ESCAPE) {
ClickManager.getSharedInstance().clearAllQueues();
Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.eject.disabled"));
chestPos = null;
active = false;
}
}
}

public void startAuswurf() {
Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.eject.enabled"));
active = true;
}

private static BlockPos getChestPos() {
Minecraft mc = Minecraft.getMinecraft();
RayTraceResult rayTraceResult = mc.objectMouseOver;

if (rayTraceResult != null && rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos blockPosition = rayTraceResult.getBlockPos();
IBlockState blockState = mc.world.getBlockState(blockPosition);

if (blockState.getBlock() instanceof BlockChest) {
return blockPosition;
}
}

return null;
}

private static Entity getEntityInBlockPos(BlockPos pos) {
Minecraft mc = Minecraft.getMinecraft();
for (Entity entity : mc.world.loadedEntityList) {
if (entity instanceof EntityLivingBase && entity.getDistanceSq(pos) < 2) {
return entity;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onKeyEvent(KeyEvent event) {
}
}
} else {
if (Addon.areKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoCompHotkey().get())) {
if (VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoCompHotkey().get())) {
startComp();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AutoDecomp {
public void onKeyEvent(KeyEvent event) {
if(Key.ESCAPE.isPressed() && autoDecompActive) {
stopDecomp();
} else if (Addon.areKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoDecompHotkey().get())) {
} else if (VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoDecompHotkey().get())) {
startDecomp();
Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.autoDecomp.started"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.labymod.api.Laby;
import net.labymod.api.client.world.item.ItemStack;
import net.labymod.api.component.data.DataComponentKey;
import net.labymod.api.event.Priority;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.input.MouseButtonEvent;
Expand All @@ -18,31 +19,27 @@ public class ItemSaver {
public static final String NBTTagStringBirthBow = "[{lvl:22s,id:48s},{lvl:4s,id:49s},{lvl:1s,id:51s},{lvl:4s,id:19s},{lvl:22s,id:21s}]";


public void mouseInput(MouseButtonEvent event) {
if(!Addon.getSharedInstance().configuration().getItemProtection().get())
return;
public void mouseButtonEvent(MouseButtonEvent event) {

if(Laby.labyAPI().minecraft().getClientPlayer() != null) {
if(Laby.labyAPI().minecraft().getClientPlayer().getMainHandItemStack() != null) {
ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().getMainHandItemStack();
if(stack.hasDataComponentContainer()) {
if(stack.getDataComponentContainer().has(DataComponentKey.simple("ench"))) {
String enchantments = stack.getDataComponentContainer().get(DataComponentKey.simple("ench")).toString();

if(stack.hasNBTTag()) {
if(stack.getNBTTag().contains("ench")) {
String enchantments = stack.getNBTTag().get("ench").toString();

//Unfortunately there is a bug within LabyMod which doesn't cancel the event in MouseButtonEvent after performing event.setCancelled(true) for some players. So switching the slot to save the item is a workaround. As LabyMod support couldn't reproduce and fix the bug this is the only option to save the item.
if(event.action() == Action.CLICK) {
if((enchantments.equals(NBTTagStringBonze) || enchantments.equals(NBTTagStringBirthSword)) && event.button().isLeft()) {
Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_sword"));
changeSlot(findHotbarSlotforItem());
Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforItem());
event.setCancelled(true);
} else if(enchantments.equals(NBTTagStringSoS) && event.button().isRight()) {
Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_sos"));
changeSlot(findHotbarSlotforBlock());
Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforBlock());
event.setCancelled(true);
} else if(enchantments.equals(NBTTagStringBirthBow) && event.button().isRight()) {
Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_birth_bow"));
changeSlot(findHotbarSlotforItem());
Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforItem());
event.setCancelled(true);
}
}
Expand Down Expand Up @@ -72,7 +69,7 @@ public static int findHotbarSlotforBlock() {
for (int i = 0; i < 9; i++) {
ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().inventory().itemStackAt(i);

if(stack.isBlock() && !stack.hasNBTTag()) {
if(stack.isBlock() && !stack.hasDataComponentContainer()) {
return i;
}
}
Expand Down Expand Up @@ -100,15 +97,12 @@ public static int findHotbarSlotforItem() {
for (int i = 0; i < 9; i++) {
ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().inventory().itemStackAt(i);

if(stack.isItem() && !stack.hasNBTTag()) {
if(stack.isItem() && !stack.hasDataComponentContainer()) {
return i;
}
}

return Laby.labyAPI().minecraft().getClientPlayer().inventory().getSelectedIndex() == 8 ? 0 : Laby.labyAPI().minecraft().getClientPlayer().inventory().getSelectedIndex() + 1;
}

public void changeSlot(int slot) {
Minecraft.getMinecraft().player.inventory.currentItem = slot;
}
}
Loading

0 comments on commit 41aded9

Please sign in to comment.