Skip to content

Commit

Permalink
Initial commit v10: 32k fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Snoworange420 committed Mar 9, 2023
1 parent 46a203f commit a36faf4
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 20 deletions.
10 changes: 9 additions & 1 deletion src/main/java/nl/snoworange/cranberry/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package nl.snoworange.cranberry;

import net.minecraft.advancements.*;
import net.minecraft.client.multiplayer.ClientAdvancementManager;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.tutorial.Tutorial;
import net.minecraft.client.tutorial.TutorialSteps;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.AdvancementEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import nl.snoworange.cranberry.features.command.CommandManager;
import nl.snoworange.cranberry.features.friend.Friend;
import nl.snoworange.cranberry.features.module.ModuleManager;
Expand All @@ -20,7 +28,7 @@ public class Main {
//Refrences
public static final String MOD_ID = "cranberry";
public static final String NAME = "Cranberry";
public static final String VERSION = "v0.7.4";
public static final String VERSION = "v0.7.6";
public static final String ACCEPTED_MINECRAFT_VERSIONS = "[1.12.2]";
public static final Logger LOGGER = LogManager.getLogger("Cranberry");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void setupItems() {
}
});
}

});
}
this.components.forEach(components -> components.getItems().sort(Comparator.comparing(ComponentFeature::getName)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public ModuleManager() {
modules.add(new SelfAnvil());
modules.add(new AutoAnvil());
modules.add(new EntityAura());
modules.add(new HopperNuker());

modules.add(new SecretClose());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import nl.snoworange.cranberry.Main;
import nl.snoworange.cranberry.features.module.Category;
import nl.snoworange.cranberry.features.module.Module;
import nl.snoworange.cranberry.features.module.modules.exploit.SecretClose;
import nl.snoworange.cranberry.features.setting.Setting;
import nl.snoworange.cranberry.util.minecraft.InventoryUtils;

Expand Down Expand Up @@ -41,7 +43,7 @@ public void onFastTick() {

if (n()) return;

if (mc.currentScreen instanceof GuiHopper) return;
if (mc.currentScreen instanceof GuiHopper || (Main.moduleManager.getModuleByName("SecretClose").isEnabled() && SecretClose.lastGui instanceof GuiHopper)) return;

if (mc.player.getHeldItemOffhand().getItem() != Items.TOTEM_OF_UNDYING) {
offhandTotemSlot = InventoryUtils.findInv(Items.TOTEM_OF_UNDYING);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package nl.snoworange.cranberry.features.module.modules.combat;

import net.minecraft.block.BlockHopper;
import net.minecraft.block.BlockShulkerBox;
import net.minecraft.network.play.client.*;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import nl.snoworange.cranberry.event.events.PacketEvent;
import nl.snoworange.cranberry.features.module.Category;
import nl.snoworange.cranberry.features.module.Module;
import nl.snoworange.cranberry.features.setting.Setting;
import nl.snoworange.cranberry.util.minecraft.BlockUtils;
import nl.snoworange.cranberry.util.minecraft.InventoryUtils;
import nl.snoworange.cranberry.util.minecraft.PlayerUtils;

public class HopperNuker extends Module {

public HopperNuker() {
super("HopperNuker",
"Nukes hoppers (?)",
Category.COMBAT
);
}

public enum BreakMode {
VANILLA,
PACKET
}

public final Setting<Boolean> rotate = register(new Setting<>("Rotate", true));
public final Setting<Boolean> swingArm = register(new Setting<>("SwingArm", true));
public final Setting<Boolean> onlyOnGround = register(new Setting<>("OnlyOnGround", true));
public final Setting<Boolean> noSelfBreaking = register(new Setting<>("NoSelfBreak", true));
public final Setting<Boolean> only32kHoppers = register(new Setting<>("Only32kHoppers", true));
public final Setting<BreakMode> breakmode = register(new Setting<>("BreakMode", BreakMode.VANILLA));
public final Setting<Integer> range = register(new Setting<>("Range", 5, 1, 7));

public BlockPos hopperPos;
public static BlockPos selfPos;

@Override
public void onEnable() {
super.onEnable();

selfPos = null;
}

@Override
public void onDisable() {
super.onDisable();
}

@Override
public void onTick() {

if (n()) return;

int pickaxeIndex = InventoryUtils.findHotbarPickaxe();

if (pickaxeIndex == -1) return;

for (BlockPos blockPos : BlockPos.getAllInBox(new BlockPos(mc.player.posX - range.getValue(), mc.player.posY - 3, mc.player.posZ - range.getValue()), new BlockPos(mc.player.posX + range.getValue(), mc.player.posY + 3, mc.player.posZ + range.getValue()))) {

if (mc.player.getDistance(blockPos.getX(), blockPos.getY(), blockPos.getZ()) <= range.getValue()
&& (only32kHoppers.getValue() ? (mc.world.getBlockState(blockPos).getBlock() instanceof BlockHopper
&& mc.world.getBlockState(blockPos.up()).getBlock() instanceof BlockShulkerBox) : (mc.world.getBlockState(blockPos).getBlock() instanceof BlockHopper))
&& (!blockPos.equals(selfPos) && noSelfBreaking.getValue())) {
hopperPos = blockPos;
break;
} else {
hopperPos = null;
}
}

if (hopperPos != null) {

int oldSlot = mc.player.inventory.currentItem;

if (onlyOnGround.getValue() && !mc.player.onGround) return;

mc.player.inventory.currentItem = pickaxeIndex;
mc.playerController.updateController();

if (rotate.getValue()) PlayerUtils.faceVector(new Vec3d(hopperPos.getX(), hopperPos.getY(), hopperPos.getZ()), true);

if (breakmode.getValue().equals(BreakMode.PACKET)) {

if (!BlockUtils.isEmptyBlock(hopperPos, false)) {
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, hopperPos, mc.player.getAdjustedHorizontalFacing()));
}

mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, hopperPos, mc.player.getAdjustedHorizontalFacing()));
} else {
mc.playerController.onPlayerDamageBlock(hopperPos, mc.player.getAdjustedHorizontalFacing());
}

if (swingArm.getValue()) mc.player.swingArm(EnumHand.MAIN_HAND);

mc.player.inventory.currentItem = oldSlot;

}
}

@SubscribeEvent
public void onPacketSend(PacketEvent.Send event) {
if (this.isEnabled()) {

if (n()) return;

if (event.getPacket() instanceof CPacketPlayerTryUseItemOnBlock) {

CPacketPlayerTryUseItemOnBlock packet = (CPacketPlayerTryUseItemOnBlock) event.getPacket();
BlockPos packetPos = packet.getPos();

if (mc.world.getBlockState(packetPos).getBlock() instanceof BlockHopper) {
selfPos = packetPos;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void searchValidPlacementForPistons(EntityPlayer target) {
&& box.intersects(target.getEntityBoundingBox())
&& target.getDistance(blockPos.getX(), blockPos.getY(), blockPos.getZ()) <= 2
&& BlockUtils.isEmptyBlock(blockPos.offset(facing), false)
&& BlockUtils.isEmptyBlock(blockPos.offset(facing, 2), false)
&& !(EnumFacing.getDirectionFromEntityLiving(blockPos, mc.player).equals(EnumFacing.DOWN) ||
EnumFacing.getDirectionFromEntityLiving(blockPos, mc.player).equals(EnumFacing.UP))
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import net.minecraft.client.gui.GuiHopper;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.network.play.client.CPacketCloseWindow;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import nl.snoworange.cranberry.Main;
import nl.snoworange.cranberry.event.events.PacketEvent;
import nl.snoworange.cranberry.features.module.Category;
import nl.snoworange.cranberry.features.module.Module;
import nl.snoworange.cranberry.features.module.modules.stronkswordmeta.Auto32k;
import nl.snoworange.cranberry.features.setting.Setting;

public class SecretClose extends Module {
Expand All @@ -20,7 +23,7 @@ public SecretClose() {

public final Setting<Boolean> onlyHopper = register(new Setting<>("OnlyHopper", true));

private static GuiScreen lastGui;
public static GuiScreen lastGui;

@Override
public void onEnable() {
Expand All @@ -32,22 +35,29 @@ public void onDisable() {
super.onDisable();
}

@Override
public void onTick() {
if (!n()) return;

if (mc.currentScreen != null) lastGui = mc.currentScreen;
@SubscribeEvent
public void onGuiSwitch(GuiOpenEvent event) {
if (mc.currentScreen != null) {
lastGui = mc.currentScreen;
}
}

@SubscribeEvent
public void onPacketSend(PacketEvent.Send event) {
if (this.isEnabled() && event.getPacket() instanceof CPacketCloseWindow) {
if (onlyHopper.getValue()) {

if (((CPacketCloseWindow) event.getPacket()).windowId == Auto32k.lastHopperGuiID
&& Main.moduleManager.getModuleByName("Auto32k").isEnabled()) {
event.setCanceled(true);
}

if (!(lastGui instanceof GuiHopper)) {
if (!(mc.currentScreen instanceof GuiHopper)) {
return;
}
}

event.setCanceled(true);
} else {
event.setCanceled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
lastHoveredStack = slot.getStack();
}
} else if (lastHoveredStack == null) {

//empty block
} else if (!enteredShulker && lastHoveredStack != slot.getStack()) {
lastHoveredStack = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package nl.snoworange.cranberry.features.module.modules.stronkswordmeta;

import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttribute;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketHeldItemChange;
import net.minecraft.network.play.client.CPacketUseEntity;
import net.minecraft.util.EnumHand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.util.math.Vec3d;
import nl.snoworange.cranberry.features.module.Category;
import nl.snoworange.cranberry.features.module.Module;
import nl.snoworange.cranberry.features.module.modules.combat.HopperNuker;
import nl.snoworange.cranberry.features.setting.Setting;
import nl.snoworange.cranberry.util.minecraft.*;
import nl.snoworange.cranberry.util.Timer;
Expand All @@ -37,6 +38,7 @@ public class Auto32k extends Module {
public int lastAirIndex = -1;
public int tickTimer = 0;
public int hopperTimer = 0;
public static int lastHopperGuiID = 0;
public boolean firstShulker = false;

Timer timer = new Timer();
Expand Down Expand Up @@ -113,9 +115,6 @@ public void onDisable() {
super.onDisable();

if (!n()) {
if (phase < 7 && mc.currentScreen instanceof GuiDispenser) {
mc.player.closeScreen();
}

if (originalSlot != -1 && !selectSwordSlot.getValue()) update(originalSlot, false);
update(mc.player.inventory.currentItem, false);
Expand Down Expand Up @@ -369,6 +368,8 @@ public void onTick() {
&& !mc.player.openContainer.inventorySlots.isEmpty()
) {

lastHopperGuiID = mc.player.openContainer.windowId;

for (int i = 0; i < 5; i++) {
if (InventoryUtils.is32k(mc.player.openContainer.inventorySlots.get(0).inventory.getStackInSlot(i))) {
overenchantedSwordIndex = i;
Expand All @@ -391,12 +392,12 @@ public void onTick() {

lastAirIndex = airIndex;

if (autoClose.getValue() && mc.currentScreen instanceof GuiHopper) mc.player.closeScreen();

if (selectSwordSlot.getValue() && (!blockShulker.getValue() || placeVertically)) update((airIndex != -1 ? airIndex : (revertedSwordIndex != -1 ? revertedSwordIndex : mc.player.inventory.currentItem)), false);

if (debug.getValue()) info("32k found in slot " + overenchantedSwordIndex);

if (autoClose.getValue() && mc.currentScreen instanceof GuiHopper) mc.player.closeScreen();

if (debug.getValue() && !blockShulker.getValue()) info("Process ended in " + timer.getPassedTimeMs() + " ms / " + tickTimer + "tx");

if (!blockShulker.getValue() || placeVertically) disable();
Expand Down Expand Up @@ -436,13 +437,13 @@ public void onTick() {

if (phase == 7) {

if (autoClose.getValue() && mc.currentScreen instanceof GuiHopper) mc.player.closeScreen();

if (selectSwordSlot.getValue()) update((lastAirIndex != -1 ? lastAirIndex : (revertedSwordIndex != -1 ? revertedSwordIndex : mc.player.inventory.currentItem)), false);

if (debug.getValue()) info("Process ended in " + timer.getPassedTimeMs() + " ms / " + tickTimer + "tx");

phase = 8;

disable();
}

if (phase == 8) {
Expand Down Expand Up @@ -549,6 +550,8 @@ public void startDispenser32k(BlockPos blockPos, EnumFacing direction) {
basePos = blockPos;
dispenserDirection = EnumFacing.UP; //does nothing because down bruh

HopperNuker.selfPos = blockPos.down(2);

phase = 1;

for (EnumFacing tempRedstoneFacing : EnumFacing.values()) {
Expand Down Expand Up @@ -576,6 +579,8 @@ public void startDispenser32k(BlockPos blockPos, EnumFacing direction) {
basePos = blockPos;
dispenserDirection = direction.getOpposite();

HopperNuker.selfPos = blockPos.offset(direction);

phase = 1;

for (EnumFacing redstoneFacing : EnumFacing.values()) {
Expand All @@ -601,6 +606,8 @@ public void startHopper32k(BlockPos blockPos) {
basePos = blockPos;
dispenserDirection = null;

HopperNuker.selfPos = blockPos;

phase = 9;
if (debug.getValue()) info("Start placing 32k using hopper");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ public static int findHotbarPiston() {
return -1;
}

public static int findHotbarPickaxe() {
for (int i = 0; i < 9; ++i) {
Item slot = mc.player.inventory.getStackInSlot(i).getItem();
if (slot instanceof ItemPickaxe) {
return i;
}
}
return -1;
}

public static int findShulkerWith32ksInside() {
for (int i = 0; i < 36; ++i) {
ItemStack itemStack = mc.player.inventory.getStackInSlot(i);
Expand Down
Loading

0 comments on commit a36faf4

Please sign in to comment.