Search in sources :

Example 16 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class SignalBlock method saveNBT.

@Override
protected void saveNBT(NBTTagCompound data) {
    super.saveNBT(data);
    //        MiscTools.writeUUID(data, "uuid", uuid);
    NBTTagList tagList = new NBTTagList();
    for (Map.Entry<WorldCoordinate, WorldCoordinate> cache : trackCache.entrySet()) {
        NBTTagCompound entry = new NBTTagCompound();
        if (cache.getKey() != null && cache.getValue() != null) {
            cache.getKey().writeToNBT(entry, "key");
            cache.getValue().writeToNBT(entry, "value");
            tagList.appendTag(entry);
        }
    }
    data.setTag("trackCache", tagList);
    //        if (RailcraftConfig.printSignalDebug()) {
    //            Deque<WorldCoordinate> test = new LinkedList<WorldCoordinate>();
    //            NBTTagList list = data.getTagList("pairings", 10);
    //            for (byte entry = 0; entry < list.tagCount(); entry++) {
    //                NBTTagCompound tag = list.getCompoundTagAt(entry);
    //                int[] c = tag.getIntArray("coords");
    //                test.add(new WorldCoordinate(c[0], c[1], c[2], c[3]));
    //            }
    //            boolean isConsistent = test.containsAll(getPairs());
    //            printDebug("Signal Block saved NBT. [{0}, {1}, {2}] [verified: {3}] [changedAspect: {4}] [data: {5}]", tile.xCoord, tile.yCoord, tile.zCoord, isConsistent, changedAspect, test);
    printDebug("Signal Block saved NBT. [{0}, {1}, {2}] [changedAspect: {3}] [data: {4}]", tile.xCoord, tile.yCoord, tile.zCoord, changedAspect, pairings);
//            savedData.put(uuid, new LinkedList<WorldCoordinate>(pairings));
//        }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 17 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class SignalBlock method loadNBT.

@Override
protected void loadNBT(NBTTagCompound data) {
    super.loadNBT(data);
    //        uuid = MiscTools.readUUID(data, "uuid");
    if (data.hasKey("trackCache")) {
        NBTTagList tagList = data.getTagList("trackCache", 10);
        for (int i = 0; i < tagList.tagCount(); i++) {
            NBTTagCompound nbt = tagList.getCompoundTagAt(i);
            WorldCoordinate key = WorldCoordinate.readFromNBT(nbt, "key");
            WorldCoordinate value = WorldCoordinate.readFromNBT(nbt, "value");
            trackCache.put(key, value);
        }
    }
    //        if (RailcraftConfig.printSignalDebug()) {
    //            String isConsistent = "unknown";
    //            Deque<WorldCoordinate> lastSave = savedData.get(uuid);
    //            if (lastSave != null) {
    //                if (pairings.containsAll(lastSave))
    //                    isConsistent = "true";
    //                else
    //                    isConsistent = "false";
    //            }
    printDebug("Signal Block loaded NBT. [{0}, {1}, {2}] [data: {3}]", tile.xCoord, tile.yCoord, tile.zCoord, pairings);
//        }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 18 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Railcraft by Railcraft.

the class ItemPairingTool method getPairData.

@Nullable
public WorldCoordinate getPairData(ItemStack stack) {
    WorldCoordinate pos = null;
    NBTTagCompound pairData = InvTools.getItemDataRailcraft(stack, PAIR_DATA_TAG);
    if (pairData != null)
        pos = WorldCoordinate.readFromNBT(pairData, COORD_TAG);
    return pos;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 19 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Railcraft by Railcraft.

the class BlockWorldspikePoint method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (heldItem != null && heldItem.getItem() instanceof IToolCrowbar) {
        IToolCrowbar crowbar = (IToolCrowbar) heldItem.getItem();
        if (crowbar.canWhack(player, hand, heldItem, pos)) {
            WorldCoordinate ourCoord = new WorldCoordinate(world.provider.getDimension(), pos);
            WorldCoordinate target = TileWorldspike.getTarget(player);
            if (target == null)
                TileWorldspike.setTarget(ourCoord, player, getUnlocalizedName());
            else if (world.provider.getDimension() != target.getDim())
                ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.worldspike.pair.fail.dimension", getUnlocalizedName());
            else if (ourCoord.equals(target)) {
                TileWorldspike.removeTarget(player);
                ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.worldspike.pair.cancel", getUnlocalizedName());
            } else {
                if (TileWorldspike.isTargetLoaded(player, target, getUnlocalizedName())) {
                    TileEntity tile = WorldPlugin.getBlockTile(world, target.getPos());
                    if (tile instanceof TileWorldspike)
                        ((TileWorldspike) tile).setPoint(player, ourCoord);
                    else if (tile != null)
                        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.worldspike.pair.fail.invalid", getUnlocalizedName());
                }
            }
            crowbar.onWhack(player, hand, heldItem, pos);
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar)

Example 20 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Railcraft by Railcraft.

the class TileWorldspike method blockActivated.

@Override
public boolean blockActivated(EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (heldItem != null && heldItem.getItem() instanceof IToolCrowbar) {
        IToolCrowbar crowbar = (IToolCrowbar) heldItem.getItem();
        if (crowbar.canWhack(player, hand, heldItem, getPos())) {
            if (Game.isHost(worldObj)) {
                WorldCoordinate ourCoord = new WorldCoordinate(this);
                WorldCoordinate target = pointPairingMap.get(player);
                if (target == null)
                    setTarget(ourCoord, player, getLocalizationTag());
                else if (worldObj.provider.getDimension() != target.getDim())
                    ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.worldspike.pair.fail.dimension", getLocalizationTag());
                else if (Objects.equals(ourCoord, target)) {
                    removeTarget(player);
                    ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.worldspike.pair.cancel", getLocalizationTag());
                } else
                    setPoint(player, target);
                crowbar.onWhack(player, hand, heldItem, getPos());
            }
            return true;
        }
    }
    return super.blockActivated(player, hand, heldItem, side, hitX, hitY, hitZ);
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) IToolCrowbar(mods.railcraft.api.core.items.IToolCrowbar)

Aggregations

WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)23 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 NBTTagList (net.minecraft.nbt.NBTTagList)6 TrackScanner (mods.railcraft.api.tracks.TrackScanner)4 TileEntity (net.minecraft.tileentity.TileEntity)4 Map (java.util.Map)3 EnumSet (java.util.EnumSet)2 HashSet (java.util.HashSet)2 IToolCrowbar (mods.railcraft.api.core.items.IToolCrowbar)2 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 ConnectType (mods.railcraft.api.charge.IElectricGrid.ChargeHandler.ConnectType)1 ConnectType (mods.railcraft.api.electricity.IElectricGrid.ChargeHandler.ConnectType)1 IControllerTile (mods.railcraft.api.signals.IControllerTile)1 IReceiverTile (mods.railcraft.api.signals.IReceiverTile)1 ISignalBlockTile (mods.railcraft.api.signals.ISignalBlockTile)1 SignalBlock (mods.railcraft.api.signals.SignalBlock)1 SignalController (mods.railcraft.api.signals.SignalController)1 SignalReceiver (mods.railcraft.api.signals.SignalReceiver)1 Block (net.minecraft.block.Block)1