Skip to content

Commit

Permalink
Keybinds (#31)
Browse files Browse the repository at this point in the history
* unbind some keybinds by default

* wrap if statements

* use resolution of the event instead of creating new one
  • Loading branch information
Alexdoru authored Jan 27, 2023
1 parent 9bb9bf4 commit a8c1212
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ else if (mc.theWorld != null) {
@SideOnly(Side.CLIENT)
public void renderGameOverlayEvent(final RenderGameOverlayEvent.Post event) {
if (event.type == RenderGameOverlayEvent.ElementType.ALL) {
statusDisplayManager.drawItemStack();
statusDisplayManager.drawItemStack(event.resolution);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,16 @@ public void tick() {
}
}

public void drawItemStack() {
public void drawItemStack(ScaledResolution resolution) {
if (ticksCounter > 0 && itemStack != null && itemStack.getItem() != null) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
RenderHelper.enableGUIStandardItemLighting();

GL11.glPushMatrix();

final Minecraft mc = Minecraft.getMinecraft();
final ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
final int y = res.getScaledHeight();

final int y = resolution.getScaledHeight();
GL11.glTranslatef(7.0f, y * 0.25f, 0);

renderItem.renderItemAndEffectIntoGUI(fontRenderer, textureManager, itemStack, 0, 0);

GL11.glPopMatrix();

RenderHelper.disableStandardItemLighting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public final class KeyBindings {

static {
placeItem = new KeyBinding("key.placeItem", Keyboard.KEY_P, References.MODNAME);
toolConfig = new KeyBinding("key.toolConfig", Keyboard.KEY_C, References.MODNAME);
toolProfileChange = new KeyBinding("key.toolProfileChange", Keyboard.KEY_BACKSLASH, References.MODNAME);
toolConfig = new KeyBinding("key.toolConfig", Keyboard.KEY_NONE, References.MODNAME);
toolProfileChange = new KeyBinding("key.toolProfileChange", Keyboard.KEY_NONE, References.MODNAME);
toggleFlight = new KeyBinding("key.toggleFlight", Keyboard.KEY_NONE, References.MODNAME);
toggleMagnet = new KeyBinding("key.toggleMagnet", Keyboard.KEY_NONE, References.MODNAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public class KeyInputHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (KeyBindings.placeItem.isPressed()) handlePlaceItemKey();
else if (KeyBindings.toolConfig.isPressed()) {
if (KeyBindings.placeItem.isPressed()) {
handlePlaceItemKey();
} else if (KeyBindings.toolConfig.isPressed()) {
DraconicEvolution.network.sendToServer(new ButtonPacket(ButtonPacket.ID_TOOLCONFIG, false));
} else if (KeyBindings.toolProfileChange.isPressed()
&& Minecraft.getMinecraft().thePlayer != null
Expand All @@ -50,19 +51,17 @@ else if (KeyBindings.toolConfig.isPressed()) {
if (player.capabilities.allowFlying) {
if (player.capabilities.isFlying) {
player.capabilities.isFlying = false;
player.sendPlayerAbilities();
} else {
player.capabilities.isFlying = true;
if (player.onGround) {
player.setPosition(player.posX, player.posY + 0.05D, player.posZ);
player.motionY = 0;
}
player.sendPlayerAbilities();
}
player.sendPlayerAbilities();
}
} else if (KeyBindings.toggleMagnet.isPressed()) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;

if (player.inventory.hasItem(ModItems.magnet)) {
DraconicEvolution.network.sendToServer(new MagnetTogglePacket());
}
Expand All @@ -73,16 +72,18 @@ private void handlePlaceItemKey() {
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
WorldClient world = Minecraft.getMinecraft().theWorld;
MovingObjectPosition mop = ToolHandler.raytraceFromEntity(world, player, 4.5D);
if (mop != null)
if (mop != null) {
DraconicEvolution.network.sendToServer(
new PlacedItemPacket((byte) mop.sideHit, mop.blockX, mop.blockY, mop.blockZ));
}
}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onMouseInput(InputEvent.MouseInputEvent event) {
if (KeyBindings.placeItem.isPressed()) handlePlaceItemKey();
else if (KeyBindings.toolConfig.isPressed()) {
if (KeyBindings.placeItem.isPressed()) {
handlePlaceItemKey();
} else if (KeyBindings.toolConfig.isPressed()) {
DraconicEvolution.network.sendToServer(new ButtonPacket(ButtonPacket.ID_TOOLCONFIG, false));
} else if (KeyBindings.toolProfileChange.isPressed() && Minecraft.getMinecraft().thePlayer != null) {
DraconicEvolution.network.sendToServer(new ButtonPacket(ButtonPacket.ID_TOOL_PROFILE_CHANGE, false));
Expand All @@ -107,7 +108,7 @@ else if (KeyBindings.toolConfig.isPressed()) {
player.inventory.currentItem = previouseSlot(1, player.inventory.currentItem);
DraconicEvolution.network.sendToServer(new TeleporterPacket(TeleporterPacket.SCROLL, -1, false));
}
} else if (change < 0) {
} else {
ItemStack item = player.inventory.getStackInSlot(previouseSlot(-1, player.inventory.currentItem));
if (item != null && item.getItem().equals(ModItems.teleporterMKII)) {
player.inventory.currentItem = previouseSlot(-1, player.inventory.currentItem);
Expand Down

0 comments on commit a8c1212

Please sign in to comment.