Skip to content

Commit

Permalink
Better support for creative mode.
Browse files Browse the repository at this point in the history
Also make the items tab be active by default.
  • Loading branch information
mattmess1221 committed Dec 19, 2016
1 parent 2b3bf30 commit bd7926e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 28 deletions.
60 changes: 54 additions & 6 deletions src/main/java/mnm/mods/itemdash/LiteModItemDash.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.SPacketSetSlot;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -55,13 +56,15 @@ public class LiteModItemDash implements Tickable, InitCompleteListener, PacketHa
private ItemStack lastRequestedStack = ItemStack.EMPTY;

@Expose
public boolean enabled = true;
private boolean visible = true;
@Expose
public String giveCommand = "/give {0} {1} {2} {3}";
private boolean survivalPick = true;
@Expose
public boolean numIds = false;
private String giveCommand = "/give {0} {1} {2} {3}";
@Expose
public ItemSorter sort = ItemSorter.DEFAULT;
private boolean numIds = false;
@Expose
private ItemSorter sort = ItemSorter.DEFAULT;

private ExcludedItems ignored = new ExcludedItems();

Expand Down Expand Up @@ -135,7 +138,7 @@ public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, bool
itemdash.onTick();
}
if (inGame) {
pbh.handleMouse();
pbh.handleMouse(this.survivalPick);
}
if (this.pickSlot) {
InventoryPlayer inv = minecraft.player.inventory;
Expand Down Expand Up @@ -179,7 +182,12 @@ public void upgradeSettings(String version, File configPath, File oldConfigPath)
public void giveItem(ItemStack stack) {
Minecraft mc = Minecraft.getMinecraft();
this.lastRequestedStack = stack;
if (mc.isSingleplayer() && mc.world.getWorldInfo().areCommandsAllowed()) {
if (mc.player.isCreative()) {
stack.setCount(1);
mc.player.inventory.setPickedItemStack(stack);
mc.playerController.sendSlotPacket(mc.player.getHeldItem(EnumHand.MAIN_HAND), 36 + mc.player.inventory.currentItem);

} else if (mc.isSingleplayer() && mc.world.getWorldInfo().areCommandsAllowed()) {
UUID uuid = mc.player.getGameProfile().getId();
MinecraftServer server = mc.getIntegratedServer();
assert server != null;
Expand Down Expand Up @@ -273,4 +281,44 @@ public static void onUpdateScreen(GuiContainer screen) {

}

public boolean isVisible() {
return visible;
}

public void setVisible(boolean visible) {
this.visible = visible;
}

public boolean isSurvivalPick() {
return survivalPick;
}

public void setSurvivalPick(boolean pick) {
this.survivalPick = pick;
}

public String getGiveCommand() {
return giveCommand;
}

public void setGiveCommand(String giveCommand) {
this.giveCommand = giveCommand;
}

public boolean isNumIds() {
return numIds;
}

public void setNumIds(boolean numIds) {
this.numIds = numIds;
}

public ItemSorter getSort() {
return sort;
}

public void setSort(ItemSorter sort) {
this.sort = sort;
}

}
4 changes: 2 additions & 2 deletions src/main/java/mnm/mods/itemdash/PickBlockHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class PickBlockHandler {
private Minecraft mc = Minecraft.getMinecraft();
private boolean cooldown;

public void handleMouse() {
if (!mc.player.capabilities.isCreativeMode) {
public void handleMouse(boolean survivalPick) {
if (mc.playerController.gameIsSurvivalOrAdventure() && survivalPick) {
if (mc.gameSettings.keyBindPickBlock.isKeyDown()) {
if (!cooldown) {
middleClickMouse();
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/mnm/mods/itemdash/gui/dash/DashSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ public class DashSettings extends Dash {

public DashSettings(ItemDash itemdash) {
super(itemdash);
this.settings.add(new BoolSetting("Legacy IDs",
it -> litemod.numIds = it, litemod.numIds));
this.settings.add(new StringSetting(this, "Give Command",
it -> litemod.giveCommand = it, litemod.giveCommand)
this.settings.add(new BoolSetting("Legacy IDs", litemod::setNumIds, litemod.isNumIds()));
this.settings.add(new BoolSetting("Survival Pick block", litemod::setSurvivalPick, litemod.isSurvivalPick()));
this.settings.add(new StringSetting(this, "Give Command", litemod::setGiveCommand, litemod.getGiveCommand())
.preset("Vanilla", "/give {0} {1} {2} {3}")
.preset("Essentials", "/i {1}:{3} {2}"));
this.settings.add(new OptionSetting<>("Sorting",
it -> litemod.sort = it, litemod.sort)
this.settings.add(new OptionSetting<>("Sorting", litemod::setSort, litemod.getSort())
.option(ItemSorter.DEFAULT, "Default")
.option(ItemSorter.BY_ID, "By ID")
.option(ItemSorter.BY_NAME, "By Name"));
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/mnm/mods/itemdash/gui/dash/ItemDash.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ public ItemDash(final Set<String> ignored, Favorites favorites) {
this.tabs.add(new SideTab(Tabs.TOGGLE.ordinal(), i++, 0, 20, false, this) {
@Override
public void drawTab() {
this.texU = isEnabled() ? 0 : 20;
this.texU = isVisible() ? 0 : 20;
super.drawTab();
}
});
// main
SideTab items = new SideTab(Tabs.ITEMS.ordinal(), i++, 80, 40, true, this);
items.active = true;
this.tabs.add(items);
// favorites
this.tabs.add(new SideTab(Tabs.FAVORITES.ordinal(), i++, 40, 40, true, this));
Expand All @@ -97,16 +98,16 @@ private void onTabActivated(@Nonnull SideTab tab) {
Tabs tabs = Tabs.values()[tab.id];
// check if the tab is active right now.
if (tab.active) {
if (isEnabled())
if (isVisible())
doSearch();
else
setEnabled(true);
setVisible(true);
return;
}
boolean open = true;
switch (tabs) {
case TOGGLE:
open = !this.isEnabled();
open = !this.isVisible();
break;
case ITEMS:
setCurrentDash(new MainDash(this, this.items));
Expand All @@ -119,8 +120,8 @@ private void onTabActivated(@Nonnull SideTab tab) {
break;

}
if (open != this.isEnabled()) {
this.setEnabled(open);
if (open != this.isVisible()) {
this.setVisible(open);
}

if (tab.activatable) {
Expand All @@ -132,16 +133,16 @@ private void onTabActivated(@Nonnull SideTab tab) {
}
}

private void setEnabled(boolean enable) {
if (isEnabled() == enable)
public void setVisible(boolean visible) {
if (isVisible() == visible)
return;
LiteModItemDash.getInstance().enabled = enable;
LiteModItemDash.getInstance().setVisible(visible);
toggleTimer = mc.ingameGUI.getUpdateCounter();
LiteModItemDash.getInstance().saveConfig();
}

private boolean isEnabled() {
return LiteModItemDash.getInstance().enabled;
private boolean isVisible() {
return LiteModItemDash.getInstance().isVisible();
}

public boolean isFocused() {
Expand Down Expand Up @@ -177,7 +178,7 @@ private void checkForGuiChanges(GuiContainer cont) {
int tick = mc.ingameGUI.getUpdateCounter() - this.toggleTimer;
EasingType easing = EasingsFactory.getInstance().quadratic();
final float time = 10;
if (!isEnabled()) {
if (!isVisible()) {
xPos = cont.width - width;
if (tick < time)
xPos = (int) easing.in().ease(tick, xPos, width, time);
Expand Down Expand Up @@ -255,7 +256,7 @@ private void doSearch() {
public void keyTyped(char key, int code) {
if (!currentDash.isFocused()) {
if (code == Keyboard.KEY_O) {
setEnabled(!isEnabled());
setVisible(!isVisible());
}
}
this.currentDash.keyTyped(key, code);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/mnm/mods/itemdash/gui/dash/MainDash.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MainDash(ItemDash itemdash, Collection<ItemStack> items) {
}

private Comparator<ItemStack> sorter() {
return LiteModItemDash.getInstance().sort.getSort();
return LiteModItemDash.getInstance().getSort().getSort();
}

private ItemIcon[][] arrangeItems(Collection<ItemStack> items) {
Expand Down Expand Up @@ -236,6 +236,7 @@ public void keyTyped(char key, int code) {
}
if (code == Keyboard.KEY_TAB) {
doSearch();
itemdash.setVisible(true);
}

if (this.search.textboxKeyTyped(key, code)) {
Expand Down

0 comments on commit bd7926e

Please sign in to comment.