mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 04:09:40 +00:00
Bug fix and small refactor (#45)
This commit is contained in:
1 parent
f1900cd9b3
commit
1e2c85f898
10 files changed
+100
-190
No files matched your search
@@ -60,6 +60,7 @@ import baubles.common.network.PacketSyncBauble;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import vazkii.botania.common.network.PacketLokiHudNotificationAck;
|
||||
|
||||
|
||||
public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeCoordinateListProvider, IManaUsingItem, IInWorldRenderable {
|
||||
@@ -129,12 +130,12 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
if(originCoords.posY == -1 && lookPos != null) {
|
||||
setOriginPos(lokiRing, lookPos.blockX, lookPos.blockY, lookPos.blockZ);
|
||||
if(player instanceof EntityPlayerMP)
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, slot), (EntityPlayerMP) player);
|
||||
syncLokiRing(player);
|
||||
} else if(lookPos != null) {
|
||||
if(originCoords.posX == lookPos.blockX && originCoords.posY == lookPos.blockY && originCoords.posZ == lookPos.blockZ) {
|
||||
clearMasterCursor(lokiRing);
|
||||
if(player instanceof EntityPlayerMP)
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, slot), (EntityPlayerMP) player);
|
||||
syncLokiRing(player);
|
||||
} else {
|
||||
addCursor : {
|
||||
int relX = lookPos.blockX - originCoords.posX;
|
||||
@@ -146,19 +147,25 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
cursors.remove(cursor);
|
||||
setCursorList(lokiRing, cursors);
|
||||
if(player instanceof EntityPlayerMP)
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, slot), (EntityPlayerMP) player);
|
||||
syncLokiRing(player);
|
||||
break addCursor;
|
||||
}
|
||||
|
||||
addCursor(lokiRing, relX, relY, relZ, getRingMirrorMode(lokiRing) );
|
||||
if(player instanceof EntityPlayerMP)
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, slot), (EntityPlayerMP) player);
|
||||
syncLokiRing(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (heldItemStack != null && event.action == Action.RIGHT_CLICK_BLOCK && lookPos != null && isRingEnabled(lokiRing)) {
|
||||
if(!ManaItemHandler.requestManaExact(lokiRing, player, cost, true)){
|
||||
renderHUDNotification(HUD_MESSAGE.INSUFFICIENT_MANA);
|
||||
if(player instanceof EntityPlayerMP){
|
||||
vazkii.botania.common.network.PacketHandler.INSTANCE.sendTo(new PacketLokiHudNotificationAck(HUD_MESSAGE.INSUFFICIENT_MANA),(EntityPlayerMP) player);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderHUDNotification(HUD_MESSAGE.INSUFFICIENT_MANA);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -170,9 +177,9 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
float oldPitch = player.rotationPitch;
|
||||
float oldYaw = player.rotationYaw;
|
||||
|
||||
int masterOffsetX = lookPos.blockX - originCoords.posX;
|
||||
int masterOffsetY = lookPos.blockY - originCoords.posY;
|
||||
int masterOffsetZ = lookPos.blockZ - originCoords.posZ;
|
||||
int masterOffsetX = originCoords.posY == -1 ? 0 :lookPos.blockX - originCoords.posX;
|
||||
int masterOffsetY = originCoords.posY == -1 ? 0 :lookPos.blockY - originCoords.posY;
|
||||
int masterOffsetZ = originCoords.posY == -1 ? 0 :lookPos.blockZ - originCoords.posZ;
|
||||
|
||||
double playerOffsetX = player.posX - originCoords.posX;
|
||||
double playerOffsetY = player.posY - originCoords.posY;
|
||||
@@ -368,17 +375,19 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
}
|
||||
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 || !isRingEnabled(lokiRing) || !isRingBreakingEnabled(lokiRing))
|
||||
if (lokiRing == null || player.worldObj.isRemote || !isRingEnabled(lokiRing) || !isRingBreakingEnabled(lokiRing))
|
||||
return;
|
||||
List<LokiCursor> cursors = getCursorList(lokiRing);
|
||||
//In case someone wants to mine ore veins with loki, this should make 1 manapool worth of mana last for 2 veins
|
||||
int cost = 30 * cursors.size();
|
||||
if (!ManaItemHandler.requestManaExact(lokiRing, player, cost, true)) {
|
||||
|
||||
if(!ManaItemHandler.requestManaExact(lokiRing, player, cost, true)){
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
vazkii.botania.common.network.PacketHandler.INSTANCE.sendTo(new PacketLokiHudNotificationAck(HUD_MESSAGE.INSUFFICIENT_MANA), (EntityPlayerMP) player);
|
||||
} else {
|
||||
renderHUDNotification(HUD_MESSAGE.INSUFFICIENT_MANA);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
ISequentialBreaker breaker = null;
|
||||
if(item instanceof ISequentialBreaker)
|
||||
breaker = (ISequentialBreaker) item;
|
||||
@@ -389,9 +398,9 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
|
||||
ChunkCoordinates originCoords = getOriginPos(lokiRing);
|
||||
|
||||
int masterOffsetX = x - originCoords.posX;
|
||||
int masterOffsetY = y - originCoords.posY;
|
||||
int masterOffsetZ = z - originCoords.posZ;
|
||||
int masterOffsetX = originCoords.posY == -1 ? 0 :x - originCoords.posX;
|
||||
int masterOffsetY = originCoords.posY == -1 ? 0 :y - originCoords.posY;
|
||||
int masterOffsetZ = originCoords.posY == -1 ? 0 :z - originCoords.posZ;
|
||||
|
||||
for(int i = 0; i < cursors.size(); i++) {
|
||||
LokiCursor cursor = cursors.get(i);
|
||||
@@ -461,7 +470,7 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
|
||||
MovingObjectPosition lookPos = Minecraft.getMinecraft().objectMouseOver;
|
||||
|
||||
if(lookPos != null && !player.worldObj.isAirBlock(lookPos.blockX, lookPos.blockY, lookPos.blockZ) && lookPos.entityHit == null) {
|
||||
if(lookPos != null && lookPos.entityHit == null) {
|
||||
List<LokiCursor> list = getCursorList(stack);
|
||||
ChunkCoordinates origin = getOriginPos(stack);
|
||||
List<ChunkCoordinates> toDraw = new ArrayList<>();
|
||||
@@ -508,6 +517,17 @@ public class ItemLokiRing extends ItemRelicBauble implements IExtendedWireframeC
|
||||
return isLokiRing(stack1) ? stack1 : isLokiRing(stack2) ? stack2 : null;
|
||||
}
|
||||
|
||||
public static int getLokiRingSlot(EntityPlayer player) {
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
|
||||
ItemStack stack1 = baubles.getStackInSlot(1);
|
||||
ItemStack stack2 = baubles.getStackInSlot(2);
|
||||
return isLokiRing(stack1) ? 1 : isLokiRing(stack2) ? 2 : null;
|
||||
}
|
||||
|
||||
public static void syncLokiRing(EntityPlayer player){
|
||||
baubles.common.network.PacketHandler.INSTANCE.sendTo(new PacketSyncBauble(player, getLokiRingSlot(player)), (EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
private static boolean isLokiRing(ItemStack stack) {
|
||||
return stack != null && (stack.getItem() == ModItems.lokiRing || stack.getItem() == ModItems.aesirRing);
|
||||
}
|
||||
|
||||
@@ -14,11 +14,8 @@ 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(PacketLokiToggleBreakingAck.class, PacketLokiToggleBreakingAck.class, 3, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketLokiClear.class, PacketLokiClear.class, 4, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketLokiClearAck.class, PacketLokiClearAck.class, 5, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketLokiMirror.class, PacketLokiMirror.class, 6, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketLokiMirrorAck.class, PacketLokiMirrorAck.class, 7, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketLokiClear.class, PacketLokiClear.class, 2, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketLokiMirror.class, PacketLokiMirror.class, 3, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketLokiHudNotificationAck.class, PacketLokiHudNotificationAck.class, 4, Side.CLIENT);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import baubles.common.network.PacketSyncBauble;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -27,8 +28,8 @@ public class PacketLokiClear implements IMessage, IMessageHandler<PacketLokiClea
|
||||
if (aRing != null) {
|
||||
ItemLokiRing.clearCursors(aRing);
|
||||
ItemLokiRing.clearMasterCursor(aRing);
|
||||
PacketLokiClearAck ackMessage = new PacketLokiClearAck();
|
||||
PacketHandler.INSTANCE.sendTo(ackMessage, player);
|
||||
ItemLokiRing.syncLokiRing(player);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketLokiHudNotificationAck(ItemLokiRing.HUD_MESSAGE.CLEAR), player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
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;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.common.item.relic.ItemLokiRing;
|
||||
|
||||
public class PacketLokiHudNotificationAck implements IMessage, IMessageHandler<PacketLokiHudNotificationAck, IMessage> {
|
||||
|
||||
|
||||
public ItemLokiRing.HUD_MESSAGE hudMessage;
|
||||
|
||||
public PacketLokiHudNotificationAck(){
|
||||
|
||||
}
|
||||
|
||||
public PacketLokiHudNotificationAck(ItemLokiRing.HUD_MESSAGE aHudMessage){
|
||||
hudMessage = aHudMessage;
|
||||
}
|
||||
@Override
|
||||
public void fromBytes(ByteBuf byteBuf) {
|
||||
int ordinal = byteBuf.readInt();
|
||||
if (ordinal >= 0 && ordinal < ItemLokiRing.HUD_MESSAGE.values().length) {
|
||||
hudMessage = ItemLokiRing.HUD_MESSAGE.values()[ordinal];
|
||||
} else {
|
||||
hudMessage = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf byteBuf) {
|
||||
byteBuf.writeInt(hudMessage.ordinal());
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IMessage onMessage(PacketLokiHudNotificationAck message, MessageContext ctx) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(mc.thePlayer) ;
|
||||
if (aRing != null && message.hudMessage != null) {
|
||||
ItemLokiRing.renderHUDNotification(message.hudMessage);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import baubles.common.network.PacketSyncBauble;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -26,8 +27,8 @@ public class PacketLokiMirror implements IMessage, IMessageHandler<PacketLokiMir
|
||||
if (aRing != null) {
|
||||
byte mode = ItemLokiRing.getRingMirrorMode(aRing);
|
||||
ItemLokiRing.setMirrorMode(aRing,(byte) ((mode+1)%8));
|
||||
PacketLokiMirrorAck ackMessage = new PacketLokiMirrorAck();
|
||||
PacketHandler.INSTANCE.sendTo(ackMessage, player);
|
||||
ItemLokiRing.syncLokiRing(player);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketLokiHudNotificationAck(ItemLokiRing.HUD_MESSAGE.MIRROR), player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
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;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.common.item.relic.ItemLokiRing;
|
||||
|
||||
public class PacketLokiMirrorAck implements IMessage, IMessageHandler<PacketLokiMirrorAck, 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(PacketLokiMirrorAck message, MessageContext ctx) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(mc.thePlayer) ;
|
||||
if (aRing != null) {
|
||||
ItemLokiRing.renderHUDNotification(ItemLokiRing.HUD_MESSAGE.MIRROR);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -28,17 +28,15 @@ public class PacketLokiToggle implements IMessage, IMessageHandler<PacketLokiTog
|
||||
if(player.isSneaking()){
|
||||
boolean ringState = !ItemLokiRing.isRingBreakingEnabled(aRing);
|
||||
ItemLokiRing.setBreakingMode(aRing, ringState);
|
||||
PacketLokiToggleBreakingAck ackMessage = new PacketLokiToggleBreakingAck();
|
||||
ackMessage.state = ringState;
|
||||
PacketHandler.INSTANCE.sendTo(ackMessage, player);
|
||||
ItemLokiRing.syncLokiRing(player);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketLokiHudNotificationAck(ItemLokiRing.HUD_MESSAGE.BREAKING), player);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean ringState = !ItemLokiRing.isRingEnabled(aRing);
|
||||
ItemLokiRing.setMode(aRing, ringState);
|
||||
PacketLokiToggleAck ackMessage = new PacketLokiToggleAck();
|
||||
ackMessage.state = ringState;
|
||||
PacketHandler.INSTANCE.sendTo(ackMessage, player);
|
||||
ItemLokiRing.syncLokiRing(player);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketLokiHudNotificationAck(ItemLokiRing.HUD_MESSAGE.MODE), player);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
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 PacketLokiToggleAck implements IMessage, IMessageHandler<PacketLokiToggleAck, 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(PacketLokiToggleAck message, MessageContext ctx) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
final ItemStack aRing = ItemLokiRing.getLokiRing(mc.thePlayer) ;
|
||||
if (aRing != null) {
|
||||
ItemLokiRing.setMode(aRing, message.state);
|
||||
ItemLokiRing.renderHUDNotification(ItemLokiRing.HUD_MESSAGE.MODE);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user