Skip to content

Commit

Permalink
Merge branch 'master' into Refill
Browse files Browse the repository at this point in the history
  • Loading branch information
0hwx authored Dec 21, 2024
2 parents 0de24e5 + 5eb37f1 commit 10bdd67
Show file tree
Hide file tree
Showing 24 changed files with 1,163 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ The Inventory Tweaks code is very unpleasant to work with. I rather write my own
- choose profile for ae2 and jei
- configurable sort sound
- animation?


### Credits
Dropoff Feature - https://www.curseforge.com/minecraft/mc-mods/dropoff - https://github.com/SCP002/DropOff/tree/1.7.10
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
dependencies {
api("com.github.GTNewHorizons:ModularUI2:2.1.16-1.7.10:dev")
api("com.github.GTNewHorizons:ModularUI:1.2.17:dev")
api("com.github.GTNewHorizons:GTNHLib:0.5.22:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.0:dev")


// api("com.github.GTNewHorizons:AdventureBackpack2:1.2.4-GTNH:dev")
Expand All @@ -51,11 +51,11 @@ dependencies {
compileOnly("com.github.GTNewHorizons:ironchest:6.0.87:dev")
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.8.4-GTNH:dev")
compileOnly("com.github.GTNewHorizons:CookingForBlockheads:1.3.7-GTNH:dev")
compileOnly("com.github.GTNewHorizons:ForestryMC:4.9.19:dev")
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.0:dev")
compileOnly("com.github.GTNewHorizons:Draconic-Evolution:1.3.14-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-502-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-503-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderStorage:1.6.4:dev")
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.11:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.13:dev")



Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Empty file modified gradlew
100644 → 100755
Empty file.
14 changes: 7 additions & 7 deletions src/main/java/com/cleanroommc/bogosorter/BogoSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cleanroommc.bogosorter.common.config.BogoSortCommandTree;
import com.cleanroommc.bogosorter.common.config.PlayerConfig;
import com.cleanroommc.bogosorter.common.config.Serializer;
import com.cleanroommc.bogosorter.common.dropoff.DropOffButtonHandler;
import com.cleanroommc.bogosorter.common.network.NetworkHandler;
import com.cleanroommc.bogosorter.common.network.NetworkUtils;
import com.cleanroommc.bogosorter.common.refill.RefillHandler;
Expand All @@ -25,12 +26,13 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.time.LocalDate;
import java.time.Month;

import static com.cleanroommc.bogosorter.ClientEventHandler.configGuiKey;
import static com.cleanroommc.bogosorter.ClientEventHandler.sortKey;
import static com.cleanroommc.bogosorter.ClientEventHandler.*;

@Mod(modid = BogoSorter.ID,
name = BogoSorter.NAME,
Expand All @@ -45,6 +47,7 @@ public class BogoSorter {
public static final String VERSION = Tags.VERSION;

public static final XSTR RND = new XSTR();
public static final Logger LOGGER = LogManager.getLogger();


@Mod.EventHandler
Expand All @@ -63,6 +66,7 @@ public void onPreInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.post(new SortConfigChangeEvent());
FMLCommonHandler.instance().bus().register(new ClientEventHandler());
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
MinecraftForge.EVENT_BUS.register(new DropOffButtonHandler());
MinecraftForge.EVENT_BUS.register(new ButtonHandler());
FMLCommonHandler.instance().bus().register(new HotbarSwap());
MinecraftForge.EVENT_BUS.register(new HotbarSwap());
Expand All @@ -75,10 +79,8 @@ public void onPostInit(FMLPostInitializationEvent event) {
if (NetworkUtils.isDedicatedClient()) {
ClientRegistry.registerKeyBinding(configGuiKey);
ClientRegistry.registerKeyBinding(sortKey);
ClientRegistry.registerKeyBinding(dropoffKey);
}
// KeyBindAPI.forceCheckKeyBind(ClientEventHandler.configGuiKey);
// KeyBindAPI.forceCheckKeyBind(ClientEventHandler.sortKey);
// KeyBindAPI.setCompatible(ClientEventHandler.sortKey, Minecraft.getMinecraft().gameSettings.keyBindPickBlock);
}

@Mod.EventHandler
Expand All @@ -100,8 +102,6 @@ public void onServerTick(TickEvent.WorldTickEvent event) {
}
}



public static boolean isAprilFools() {
LocalDate date = LocalDate.now();
return date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1;
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/com/cleanroommc/bogosorter/ClientEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import com.cleanroommc.bogosorter.api.SortRule;
import com.cleanroommc.bogosorter.common.config.BogoSorterConfig;
import com.cleanroommc.bogosorter.common.config.ConfigGui;
import com.cleanroommc.bogosorter.common.config.PlayerConfig;
import com.cleanroommc.bogosorter.common.dropoff.DropOffHandler;
import com.cleanroommc.bogosorter.common.dropoff.render.RendererCube;
import com.cleanroommc.bogosorter.common.network.CSort;
import com.cleanroommc.bogosorter.common.network.CDropOff;
import com.cleanroommc.bogosorter.common.network.NetworkHandler;
import com.cleanroommc.bogosorter.common.sort.ClientSortData;
import com.cleanroommc.bogosorter.common.sort.GuiSortingContext;
Expand Down Expand Up @@ -37,7 +41,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
Expand All @@ -54,6 +58,7 @@ public class ClientEventHandler {
public static final List<ItemStack> allItems = new ArrayList<>();
public static final KeyBinding configGuiKey = new KeyBinding("key.sort_config", Keyboard.KEY_K, "key.categories.bogosorter");
public static final KeyBinding sortKey = new KeyBinding("key.sort", -98, "key.categories.bogosorter");
public static final KeyBinding dropoffKey = new KeyBinding("key.dropoff", Keyboard.KEY_SEMICOLON, "key.categories.bogosorter");
public static final boolean isDeobfuscatedEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");

public static final KeyBind moveAllSame = KeyBind.builder("move_all_same")
Expand Down Expand Up @@ -86,6 +91,7 @@ public class ClientEventHandler {
private static long timeConfigGui = 0;
private static long timeSort = 0;
private static long timeShortcut = 0;
private static long timeDropoff = 0;
private static long ticks = 0;

private static GuiScreen nextGui = null;
Expand Down Expand Up @@ -147,6 +153,15 @@ public void onKeyInput(InputEvent.KeyInputEvent event) {
timeConfigGui = t;
}
}
if (Keypress(dropoffKey)){
long t = Minecraft.getSystemTime();
if (t - timeDropoff > 500) {
if (DropOffHandler.enableDroppOff){
NetworkHandler.sendToServer(new CDropOff());
}
timeDropoff = t;
}
}
handleInput(null);
}

Expand Down Expand Up @@ -199,6 +214,13 @@ public void onMouseInput(MouseInputEvent.Pre event) {
}
}

@SubscribeEvent
public void onRenderWorldLastEvent(RenderWorldLastEvent event) {
if (DropOffHandler.dropoffRender){
RendererCube.INSTANCE.tryToRender(event);
}
}

// handle all inputs in one method
public static boolean handleInput(@Nullable GuiContainer container) {
// if (container != null) {// && container.isFocused()) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/cleanroommc/bogosorter/common/McUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import com.cleanroommc.modularui.utils.item.IItemHandler;
import com.cleanroommc.modularui.utils.item.ItemHandlerHelper;
import com.cleanroommc.modularui.utils.item.PlayerMainInvWrapper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -85,4 +91,13 @@ public static ItemStack insertItem(IItemHandler dest, @Nonnull ItemStack stack,

return stack;
}

@SideOnly(Side.CLIENT)
public static void playSound(String sound) {
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
ResourceLocation resourceLocation = new ResourceLocation(sound);
PositionedSoundRecord record = PositionedSoundRecord.func_147674_a(resourceLocation, 1.0f);

soundHandler.playSound(record);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.cleanroommc.bogosorter.BogoSortAPI;
import com.cleanroommc.bogosorter.api.SortRule;
import com.cleanroommc.bogosorter.common.HotbarSwap;
import com.cleanroommc.bogosorter.common.dropoff.DropOffButtonHandler;
import com.cleanroommc.bogosorter.common.dropoff.DropOffHandler;
import com.cleanroommc.bogosorter.common.sort.NbtSortRule;
import com.cleanroommc.bogosorter.common.sort.SortHandler;
import com.cleanroommc.bogosorter.core.BogoSorterCore;
Expand Down Expand Up @@ -38,6 +40,11 @@ public static void save(JsonObject json) {
JsonObject general = new JsonObject();
general.addProperty("enableAutoRefill", playerConfig.enableAutoRefill);
general.addProperty("refillDmgThreshold", playerConfig.autoRefillDamageThreshold);
general.addProperty("enableDropoff", DropOffHandler.enableDroppOff);
general.addProperty("dropoffRender",DropOffHandler.dropoffRender);
general.addProperty("dropoffChatMessage",DropOffHandler.dropoffChatMessage);
general.addProperty("dropoffButtonX", DropOffButtonHandler.buttonX);
general.addProperty("dropoffButtonY",DropOffButtonHandler.buttonY);
general.addProperty("enableHotbarSwap", HotbarSwap.isEnabled());
general.addProperty("sortSound", SortHandler.getSortSoundName());
general.addProperty("buttonColor", "#" + Integer.toHexString(buttonColor));
Expand Down Expand Up @@ -75,6 +82,11 @@ public static void load(JsonObject json) {
JsonObject general = json.getAsJsonObject("General");
playerConfig.enableAutoRefill = JsonHelper.getBoolean(general, true, "enableAutoRefill");
playerConfig.autoRefillDamageThreshold = (short) JsonHelper.getInt(general, 1, "refillDmgThreshold");
DropOffHandler.enableDroppOff = JsonHelper.getBoolean(general, true, "enableDropoff");
DropOffHandler.dropoffRender = JsonHelper.getBoolean(general, true, "dropoffRender");
DropOffHandler.dropoffChatMessage = JsonHelper.getBoolean(general, true, "dropoffChatMessage");
DropOffButtonHandler.buttonX = JsonHelper.getInt(general, 80, "dropoffButtonX");
DropOffButtonHandler.buttonY = JsonHelper.getInt(general, 12, "dropoffButtonY");
HotbarSwap.setEnabled(JsonHelper.getBoolean(general, true, "enableHotbarSwap"));
// SortHandler.sortSound = JsonHelper.getElement(general, SoundEvents.UI_BUTTON_CLICK, element -> {
// if (element.isJsonNull()) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.cleanroommc.bogosorter.api.SortRule;
import com.cleanroommc.bogosorter.common.HotbarSwap;
import com.cleanroommc.bogosorter.common.SortConfigChangeEvent;
import com.cleanroommc.bogosorter.common.dropoff.DropOffHandler;
import com.cleanroommc.bogosorter.common.sort.NbtSortRule;
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.drawable.IKey;
Expand Down Expand Up @@ -165,7 +166,49 @@ public IWidget createGeneralConfigUI(GuiContext context) {
.marginLeft(10)
.height(14)
.addTooltipLine(IKey.lang("bogosort.gui.hotbar_scrolling.tooltip"))
.tooltipShowUpTimer(10)));
.tooltipShowUpTimer(10)))
.child(new Row()
.widthRel(1f).height(14)
.margin(0, 2)
.child(new CycleButtonWidget()
.value(new BoolValue.Dynamic(() -> DropOffHandler.enableDroppOff, val -> DropOffHandler.enableDroppOff = val))
.stateOverlay(TOGGLE_BUTTON)
.disableHoverBackground()
.size(14, 14)
.margin(8, 0)
.background(IDrawable.EMPTY))
.child(IKey.lang("bogosort.gui.dropoff_enable").asWidget()
.height(14)
.marginLeft(10)
.expanded()))
.child(new Row()
.widthRel(1f).height(14)
.margin(0, 2)
.child(new CycleButtonWidget()
.value(new BoolValue.Dynamic(() -> DropOffHandler.dropoffRender, val -> DropOffHandler.dropoffRender = val))
.stateOverlay(TOGGLE_BUTTON)
.disableHoverBackground()
.size(14, 14)
.margin(8, 0)
.background(IDrawable.EMPTY))
.child(IKey.lang("bogosort.gui.dropoff_render").asWidget()
.height(14)
.marginLeft(10)
.expanded()))
.child(new Row()
.widthRel(1f).height(14)
.margin(0, 2)
.child(new CycleButtonWidget()
.value(new BoolValue.Dynamic(() -> DropOffHandler.dropoffChatMessage, val -> DropOffHandler.dropoffChatMessage = val))
.stateOverlay(TOGGLE_BUTTON)
.disableHoverBackground()
.size(14, 14)
.margin(8, 0)
.background(IDrawable.EMPTY))
.child(IKey.lang("bogosort.gui.dropoff_chatmessage").asWidget()
.height(14)
.marginLeft(10)
.expanded()));
}

public IWidget createProfilesConfig(GuiContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.PacketBuffer;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.service.IPropertyKey;

import java.util.Map;

public class PlayerConfig {

private static final Map<EntityPlayerMP, PlayerConfig> playerConfig = new Object2ObjectOpenHashMap<>();
private static final PlayerConfig CLIENT = new PlayerConfig();

public boolean enableAutoRefill = true;
public int autoRefillDamageThreshold = 1;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.cleanroommc.bogosorter.common.dropoff;

import com.cleanroommc.bogosorter.BogoSorter;
import com.cleanroommc.bogosorter.ClientEventHandler;
import com.cleanroommc.bogosorter.common.sort.ButtonHandler;
import com.cleanroommc.bogosorter.common.sort.IGuiContainerAccessor;
import com.cleanroommc.modularui.screen.GuiScreenWrapper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraftforge.client.event.GuiScreenEvent;

public class DropOffButtonHandler {

public static int buttonX = 80;
public static int buttonY = 12;

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
GuiScreen screen = event.gui;
if (screen instanceof GuiContainerCreative) {
return;
}
try {
if (screen instanceof InventoryEffectRenderer inv) {
event.buttonList.add(new InvButton(inv));
}
} catch (NullPointerException e) {
BogoSorter.LOGGER.error(
"Erroring adding dropoff button to player inventory \n" + e);
}
}


@SubscribeEvent
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
GuiScreen screen = event.gui;

if (screen instanceof InventoryEffectRenderer) {
for (GuiButton guiButton : ((IGuiContainerAccessor) event.gui).getButtons()) {
if (guiButton instanceof InvButton invButton) {
invButton.drawTooltip(event.mouseX, event.mouseY);
}
}
}
}
}
Loading

0 comments on commit 10bdd67

Please sign in to comment.