mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 04:09:40 +00:00
Add keybind to clear selected blocks
also stop selected blocks from drawing with ring turned off
This commit is contained in:
1 parent
d24f3facfe
commit
cf60696c68
7 files changed
+117
-7
No files matched your search
@@ -2,6 +2,7 @@ package vazkii.botania.client.core.handler;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
import vazkii.botania.common.network.PacketLokiClear;
|
||||
import vazkii.botania.common.network.PacketLokiToggle;
|
||||
import vazkii.botania.common.network.PacketLokiToggleBreaking;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
@@ -15,11 +16,14 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class KeyHandler {
|
||||
private static final KeyBinding keyToggleRingOfLoki= new KeyBinding("botaniamisc.toggleLoki", 0, "botaniamisc.keyCategory");
|
||||
private static final KeyBinding keyToggleRingOfLokiBreaking= new KeyBinding("botaniamisc.toggleLokiBreaking", 0, "botaniamisc.keyCategory");
|
||||
private static final KeyBinding keyRingOfLokiClear= new KeyBinding("botaniamisc.ringOfLokiClear", 0, "botaniamisc.keyCategory");
|
||||
|
||||
public KeyHandler() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
ClientRegistry.registerKeyBinding(keyToggleRingOfLoki);
|
||||
ClientRegistry.registerKeyBinding(keyToggleRingOfLokiBreaking);
|
||||
ClientRegistry.registerKeyBinding(keyToggleRingOfLokiBreaking);
|
||||
ClientRegistry.registerKeyBinding(keyRingOfLokiClear);
|
||||
|
||||
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -35,6 +39,9 @@ public class KeyHandler {
|
||||
if(keyToggleRingOfLokiBreaking.isPressed()){
|
||||
toggleRingLokiBreaking();
|
||||
}
|
||||
if(keyRingOfLokiClear.isPressed()){
|
||||
ringOfLokiClear();
|
||||
}
|
||||
}
|
||||
|
||||
private static void toggleRingLoki() {
|
||||
@@ -44,4 +51,7 @@ public class KeyHandler {
|
||||
private static void toggleRingLokiBreaking() {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketLokiToggleBreaking());
|
||||
}
|
||||
private static void ringOfLokiClear() {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketLokiClear());
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
private boolean recursion = false;
|
||||
|
||||
public static enum HUD_MESSAGE {
|
||||
MODE, BREAKING
|
||||
MODE, BREAKING, CLEAR
|
||||
}
|
||||
|
||||
public ItemLokiRing() {
|
||||
@@ -122,12 +122,12 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
if (heldItemStack == null && event.action == Action.RIGHT_CLICK_BLOCK && player.isSneaking() && isRingEnabled(lokiRing)) {
|
||||
if(originCoords.posY == -1 && lookPos != null) {
|
||||
setOriginPos(lokiRing, lookPos.blockX, lookPos.blockY, lookPos.blockZ);
|
||||
setCursorList(lokiRing, null);
|
||||
clearCursors(lokiRing);
|
||||
if(player instanceof EntityPlayerMP)
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, slot), (EntityPlayerMP) player);
|
||||
} else if(lookPos != null) {
|
||||
if(originCoords.posX == lookPos.blockX && originCoords.posY == lookPos.blockY && originCoords.posZ == lookPos.blockZ) {
|
||||
setOriginPos(lokiRing, 0, -1, 0);
|
||||
clearMasterCursor(lokiRing);
|
||||
if(player instanceof EntityPlayerMP)
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, slot), (EntityPlayerMP) player);
|
||||
} else {
|
||||
@@ -215,6 +215,9 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
case BREAKING:
|
||||
text = getLokiBreakingModeText(getLokiRing(mc.thePlayer));
|
||||
break;
|
||||
case CLEAR:
|
||||
text = getLokiCearText(getLokiRing(mc.thePlayer));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
@@ -222,6 +225,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
|
||||
GTNHLib.proxy.printMessageAboveHotbar(text, 60, true, true);
|
||||
}
|
||||
|
||||
public static String getLokiModeText(ItemStack stack){
|
||||
return EnumChatFormatting.GOLD + StatCollector.translateToLocal("item.botania:lokiRing.name") + " " + (isRingEnabled(stack) ?
|
||||
EnumChatFormatting.GREEN + StatCollector.translateToLocal("botaniamisc.lokiOn") :
|
||||
@@ -235,6 +239,11 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
EnumChatFormatting.RED + StatCollector.translateToLocal("botaniamisc.lokiOff"));
|
||||
}
|
||||
|
||||
public static String getLokiCearText(ItemStack stack){
|
||||
return EnumChatFormatting.GOLD + StatCollector.translateToLocal("botaniamisc.lokiClear") ;
|
||||
|
||||
}
|
||||
|
||||
public static boolean isRingEnabled (final ItemStack stack){
|
||||
return stack.stackTagCompound.getBoolean(TAG_MODE);
|
||||
}
|
||||
@@ -275,13 +284,15 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
|
||||
@Override
|
||||
public void onUnequipped(ItemStack stack, EntityLivingBase player) {
|
||||
setCursorList(stack, null);
|
||||
clearCursors(stack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<ChunkCoordinates> getWireframesToDraw(EntityPlayer player, ItemStack stack) {
|
||||
if(getLokiRing(player) != stack)
|
||||
ItemStack lokiRing = getLokiRing(player);
|
||||
if(lokiRing != stack || !isRingEnabled(lokiRing) )
|
||||
return null;
|
||||
|
||||
MovingObjectPosition lookPos = Minecraft.getMinecraft().objectMouseOver;
|
||||
@@ -310,7 +321,14 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getSourceWireframe(EntityPlayer player, ItemStack stack) {
|
||||
return getLokiRing(player) == stack ? getOriginPos(stack) : null;
|
||||
return getLokiRing(player) == stack && isRingEnabled(stack) ? getOriginPos(stack) : null;
|
||||
}
|
||||
|
||||
public static void clearCursors(ItemStack stack){
|
||||
setCursorList(stack, null);
|
||||
}
|
||||
public static void clearMasterCursor(ItemStack stack){
|
||||
setOriginPos(stack, 0, -1, 0);
|
||||
}
|
||||
|
||||
public static ItemStack getLokiRing(EntityPlayer player) {
|
||||
|
||||
@@ -17,5 +17,7 @@ public class PacketHandler {
|
||||
INSTANCE.registerMessage(PacketLokiToggleAck.class, PacketLokiToggleAck.class, 2, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketLokiToggleBreaking.class, PacketLokiToggleBreaking.class, 3, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketLokiToggleBreakingAck.class, PacketLokiToggleBreakingAck.class, 4, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketLokiClear.class, PacketLokiClear.class, 5, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketLokiClearAck.class, PacketLokiClearAck.class, 6, Side.CLIENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.common.item.relic.ItemLokiRing;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketLokiClear implements IMessage, IMessageHandler<PacketLokiClear, IMessage> {
|
||||
@Override
|
||||
public void fromBytes(ByteBuf byteBuf) {
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf byteBuf) {
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketLokiClear message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(player);
|
||||
if (aRing != null) {
|
||||
ItemLokiRing.clearCursors(aRing);
|
||||
ItemLokiRing.clearMasterCursor(aRing);
|
||||
PacketLokiClearAck ackMessage = new PacketLokiClearAck();
|
||||
PacketHandler.INSTANCE.sendTo(ackMessage, player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.common.item.relic.ItemLokiRing;
|
||||
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 cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketLokiClearAck implements IMessage, IMessageHandler<PacketLokiClearAck, IMessage> {
|
||||
|
||||
public boolean state;
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf byteBuf) {
|
||||
state = byteBuf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf byteBuf) {
|
||||
byteBuf.writeBoolean(state);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IMessage onMessage(PacketLokiClearAck message, MessageContext ctx) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(mc.thePlayer) ;
|
||||
if (aRing != null) {
|
||||
|
||||
ItemLokiRing.renderHUDNotification(ItemLokiRing.HUD_MESSAGE.CLEAR);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user