mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-13 16:54:06 +00:00
1 parent
93e6a1f7ba
commit
5cdf19daac
8 files changed
+162
-11
No files matched your search
@@ -3,6 +3,7 @@ package vazkii.botania.client.core.handler;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
import vazkii.botania.common.network.PacketLokiToggle;
|
||||
import vazkii.botania.common.network.PacketLokiToggleBreaking;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -13,10 +14,13 @@ 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");
|
||||
|
||||
public KeyHandler() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
ClientRegistry.registerKeyBinding(keyToggleRingOfLoki);
|
||||
ClientRegistry.registerKeyBinding(keyToggleRingOfLoki);
|
||||
ClientRegistry.registerKeyBinding(keyToggleRingOfLokiBreaking);
|
||||
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
@@ -28,9 +32,16 @@ public class KeyHandler {
|
||||
if (keyToggleRingOfLoki.isPressed()){
|
||||
toggleRingLoki();
|
||||
}
|
||||
if(keyToggleRingOfLokiBreaking.isPressed()){
|
||||
toggleRingLokiBreaking();
|
||||
}
|
||||
}
|
||||
|
||||
private static void toggleRingLoki() {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketLokiToggle());
|
||||
}
|
||||
|
||||
private static void toggleRingLokiBreaking() {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketLokiToggleBreaking());
|
||||
}
|
||||
}
|
||||
@@ -30,13 +30,17 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import vazkii.botania.api.item.IExtendedWireframeCoordinateListProvider;
|
||||
import vazkii.botania.api.item.ISequentialBreaker;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.common.achievement.ModAchievements;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.item.ItemTemperanceStone;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.item.equipment.tool.ToolCommons;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
@@ -49,6 +53,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeCoordinateListProvider, IManaUsingItem {
|
||||
|
||||
private static final String TAG_CURSOR_LIST = "cursorList";
|
||||
@@ -61,13 +66,32 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
private static final String TAG_Y_ORIGIN = "yOrigin";
|
||||
private static final String TAG_Z_ORIGIN = "zOrigin";
|
||||
private static final String TAG_MODE = "mode";
|
||||
private static final String TAG_BREAKING_MODE = "breaking";
|
||||
private boolean recursion = false;
|
||||
|
||||
public static enum HUD_MESSAGE {
|
||||
MODE, BREAKING
|
||||
}
|
||||
|
||||
public ItemLokiRing() {
|
||||
super(LibItemNames.LOKI_RING);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBlockBreak(BlockEvent.BreakEvent event) {
|
||||
EntityPlayer player = event.getPlayer();
|
||||
int x = event.x;
|
||||
int y = event.y;
|
||||
int z = event.z;
|
||||
int side = event.blockMetadata;
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if(stack == null) return;
|
||||
Item item = player.getCurrentEquippedItem().getItem();
|
||||
breakOnAllCursors(player, item, stack, x, y, z, side);
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(recursion) return;
|
||||
@@ -170,13 +194,32 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
player.posZ = oldPosZ;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setMode(ItemStack stack, boolean state) {
|
||||
stack.stackTagCompound.setBoolean(TAG_MODE, state);
|
||||
}
|
||||
|
||||
public static void setBreakingMode(ItemStack stack, boolean state) {
|
||||
stack.stackTagCompound.setBoolean(TAG_BREAKING_MODE, state);
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void renderHUDNotification(){
|
||||
public static void renderHUDNotification(HUD_MESSAGE type){
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
String text = getLokiModeText(getLokiRing(mc.thePlayer));
|
||||
String text;
|
||||
switch (type) {
|
||||
case MODE:
|
||||
text = getLokiModeText(getLokiRing(mc.thePlayer));
|
||||
break;
|
||||
case BREAKING:
|
||||
text = getLokiBreakingModeText(getLokiRing(mc.thePlayer));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
GTNHLib.proxy.printMessageAboveHotbar(text, 60, true, true);
|
||||
}
|
||||
public static String getLokiModeText(ItemStack stack){
|
||||
@@ -184,20 +227,34 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
EnumChatFormatting.GREEN + StatCollector.translateToLocal("botaniamisc.lokiOn") :
|
||||
EnumChatFormatting.RED + StatCollector.translateToLocal("botaniamisc.lokiOff"));
|
||||
}
|
||||
|
||||
public static String getLokiBreakingModeText(ItemStack stack){
|
||||
return EnumChatFormatting.GOLD + StatCollector.translateToLocal("item.botania:lokiRing.name") + " "+
|
||||
StatCollector.translateToLocal("botaniamisc.breaking") + " " + (isRingBreakingEnabled(stack) ?
|
||||
EnumChatFormatting.GREEN + StatCollector.translateToLocal("botaniamisc.lokiOn") :
|
||||
EnumChatFormatting.RED + StatCollector.translateToLocal("botaniamisc.lokiOff"));
|
||||
}
|
||||
|
||||
public static boolean isRingEnabled (final ItemStack stack){
|
||||
return stack.stackTagCompound.getBoolean(TAG_MODE);
|
||||
}
|
||||
|
||||
public static boolean isRingBreakingEnabled (final ItemStack stack){
|
||||
return stack.stackTagCompound.getBoolean(TAG_BREAKING_MODE);
|
||||
}
|
||||
|
||||
public static void breakOnAllCursors(EntityPlayer player, Item item, ItemStack stack, int x, int y, int z, int side) {
|
||||
ItemStack lokiRing = getLokiRing(player);
|
||||
if(lokiRing == null || player.worldObj.isRemote || !(item instanceof ISequentialBreaker))
|
||||
if(lokiRing == null || player.worldObj.isRemote || !isRingEnabled(lokiRing) || !isRingBreakingEnabled(lokiRing))
|
||||
return;
|
||||
|
||||
List<ChunkCoordinates> cursors = getCursorList(lokiRing);
|
||||
ISequentialBreaker breaker = (ISequentialBreaker) item;
|
||||
ISequentialBreaker breaker = null;
|
||||
if(item instanceof ISequentialBreaker)
|
||||
breaker = (ISequentialBreaker) item;
|
||||
World world = player.worldObj;
|
||||
boolean silk = EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, stack) > 0;
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack);
|
||||
boolean dispose = breaker.disposeOfTrashBlocks(stack);
|
||||
boolean dispose = breaker == null? true : breaker.disposeOfTrashBlocks(stack);
|
||||
|
||||
for(int i = 0; i < cursors.size(); i++) {
|
||||
ChunkCoordinates coords = cursors.get(i);
|
||||
@@ -205,8 +262,9 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
int yp = y + coords.posY;
|
||||
int zp = z + coords.posZ;
|
||||
Block block = world.getBlock(xp, yp, zp);
|
||||
breaker.breakOtherBlock(player, stack, xp, yp, zp, x, y, z, side);
|
||||
ToolCommons.removeBlockWithDrops(player, stack, player.worldObj, xp, yp, zp, x, y, z, block, new Material[] { block.getMaterial() }, silk, fortune, block.getBlockHardness(world, xp, yp, zp), dispose);
|
||||
if(breaker != null)
|
||||
breaker.breakOtherBlock(player, stack, xp, yp, zp, x, y, z, side);
|
||||
ToolCommons.removeBlockWithDrops(player, stack, player.worldObj, xp, yp, zp, x, y, z, block, new Material[] { block.getMaterial() }, silk, fortune, block.getBlockHardness(world, xp, yp, zp), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,5 +15,7 @@ public class PacketHandler {
|
||||
public static void initPackets() {
|
||||
INSTANCE.registerMessage(PacketLokiToggle.class, PacketLokiToggle.class, 1, Side.SERVER);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -33,7 +32,7 @@ public class PacketLokiToggleAck implements IMessage, IMessageHandler<PacketLoki
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(mc.thePlayer) ;
|
||||
if (aRing != null) {
|
||||
ItemLokiRing.setMode(aRing, message.state);
|
||||
ItemLokiRing.renderHUDNotification();
|
||||
ItemLokiRing.renderHUDNotification(ItemLokiRing.HUD_MESSAGE.MODE);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
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 PacketLokiToggleBreaking implements IMessage, IMessageHandler<PacketLokiToggleBreaking, IMessage> {
|
||||
@Override
|
||||
public void fromBytes(ByteBuf byteBuf) {
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf byteBuf) {
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketLokiToggleBreaking message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(player);
|
||||
if (aRing != null) {
|
||||
boolean ringState = !ItemLokiRing.isRingBreakingEnabled(aRing);
|
||||
ItemLokiRing.setBreakingMode(aRing, ringState);
|
||||
PacketLokiToggleBreakingAck ackMessage = new PacketLokiToggleBreakingAck();
|
||||
ackMessage.state = ringState;
|
||||
PacketHandler.INSTANCE.sendTo(ackMessage, player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
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 PacketLokiToggleBreakingAck implements IMessage, IMessageHandler<PacketLokiToggleBreakingAck, 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(PacketLokiToggleBreakingAck message, MessageContext ctx) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(mc.thePlayer) ;
|
||||
if (aRing != null) {
|
||||
ItemLokiRing.setBreakingMode(aRing, message.state);
|
||||
ItemLokiRing.renderHUDNotification(ItemLokiRing.HUD_MESSAGE.BREAKING);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -156,8 +156,10 @@ botaniamisc.santaweaveInfo=Manaweave, changed up for the &cs&fe&ca&fs&co&fn
|
||||
botaniamisc.enterToView=^ Press ENTER to view ^
|
||||
botaniamisc.keyCategory=Botania
|
||||
botaniamisc.toggleLoki=Toggle Ring of Loki
|
||||
botaniamisc.toggleLokiBreaking=Toggle Ring of Loki Breaking
|
||||
botaniamisc.lokiOn=On
|
||||
botaniamisc.lokiOff=Off
|
||||
botaniamisc.breaking=Breaking
|
||||
|
||||
# NEI INTEGRATION
|
||||
botania.nei.brewery=Botanical Brewery
|
||||
|
||||
@@ -156,8 +156,10 @@ botaniamisc.santaweaveInfo=Манаткань изменилась из-за &c
|
||||
botaniamisc.enterToView=^ Нажмите ENTER для просмотра ^
|
||||
botaniamisc.keyCategory=Botania
|
||||
botaniamisc.toggleLoki=Переключение режимов Кольца Локи
|
||||
botaniamisc.toggleLokiBreaking=Переключение режимов ломания Кольца Локи
|
||||
botaniamisc.lokiOn=Вкл.
|
||||
botaniamisc.lokiOff=Выкл.
|
||||
botaniamisc.breaking=Ломание
|
||||
|
||||
# NEI INTEGRATION
|
||||
botania.nei.brewery=Ботаническая зельеварка
|
||||
|
||||
Reference in new issue
Block a user