-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
181 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 44 additions & 1 deletion
45
src/main/java/reobf/proghatches/keybinding/KeyBindings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,50 @@ | ||
package reobf.proghatches.keybinding; | ||
|
||
import cpw.mods.fml.client.registry.ClientRegistry; | ||
import cpw.mods.fml.common.FMLCommonHandler; | ||
import cpw.mods.fml.common.eventhandler.EventPriority; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import cpw.mods.fml.common.gameevent.TickEvent; | ||
import cpw.mods.fml.common.gameevent.TickEvent.Phase; | ||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import net.minecraft.client.settings.KeyBinding; | ||
import reobf.proghatches.main.MyMod; | ||
import reobf.proghatches.net.SwitchModeMessage; | ||
|
||
public class KeyBindings { | ||
public static KeyBinding key = new KeyBinding("switch", 0, "programmable hatches key"); | ||
|
||
@SideOnly(Side.CLIENT) | ||
public KeyBinding key; | ||
|
||
interface Run { | ||
public default void run() { | ||
} | ||
} | ||
|
||
{ | ||
|
||
((Run) new Run() { | ||
@SideOnly(Side.CLIENT) | ||
@Override | ||
public void run() { | ||
key = new KeyBinding("proghatch.keybinding.kit.switch.desc", 0, "itemGroup.proghatches"); | ||
ClientRegistry.registerKeyBinding(key); | ||
FMLCommonHandler.instance().bus().register(KeyBindings.this); | ||
} | ||
}).run(); | ||
|
||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
@SubscribeEvent(priority = EventPriority.HIGH, receiveCanceled = false) | ||
public void tick(final TickEvent.ClientTickEvent event) { | ||
if (key.isPressed()) { | ||
|
||
MyMod.net.sendToServer(new SwitchModeMessage()); | ||
|
||
} | ||
; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/reobf/proghatches/net/SwitchModeMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package reobf.proghatches.net; | ||
|
||
import baubles.api.BaublesApi; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessage; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; | ||
import cpw.mods.fml.common.network.simpleimpl.MessageContext; | ||
import io.netty.buffer.ByteBuf; | ||
import net.minecraft.inventory.IInventory; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.NetHandlerPlayServer; | ||
import net.minecraft.util.ChatComponentText; | ||
import net.minecraft.util.ChatComponentTranslation; | ||
import reobf.proghatches.item.ItemProgrammingToolkit; | ||
import tconstruct.armor.player.TPlayerStats; | ||
|
||
public class SwitchModeMessage implements IMessage { | ||
|
||
|
||
public SwitchModeMessage(){} | ||
public static class Handler implements IMessageHandler<SwitchModeMessage, SwitchModeMessage> { | ||
|
||
@Override | ||
public SwitchModeMessage onMessage(SwitchModeMessage message, MessageContext ctx) { | ||
|
||
IInventory[] invs = | ||
{TPlayerStats.get(((NetHandlerPlayServer)ctx.netHandler).playerEntity).armor, | ||
BaublesApi.getBaubles(((NetHandlerPlayServer)ctx.netHandler).playerEntity) | ||
}; | ||
|
||
for(IInventory inv:invs) | ||
for(int i=0;i<inv.getSizeInventory();i++){ | ||
ItemStack is = inv.getStackInSlot(i); | ||
if(is!=null&&is.getItem() instanceof ItemProgrammingToolkit){ | ||
is.setItemDamage((is.getItemDamage() + 1) % ItemProgrammingToolkit.maxModes); | ||
((NetHandlerPlayServer)ctx.netHandler).playerEntity.addChatMessage(new | ||
|
||
ChatComponentTranslation("proghatch.keybinding.kit.switch.mode."+(is.getItemDamage())) | ||
); | ||
break; | ||
//((ItemProgrammingToolkit)is.getItem()).onItemRightClick(is, null, null); | ||
} | ||
|
||
} | ||
return null; | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) { | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) { | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters