Search in sources :

Example 1 with PacketSecurityUpdate

use of mekanism.common.network.to_client.PacketSecurityUpdate in project Mekanism by mekanism.

the class CommonPlayerTracker method onPlayerLoginEvent.

@SubscribeEvent
public void onPlayerLoginEvent(PlayerLoggedInEvent event) {
    PlayerEntity player = event.getPlayer();
    if (!player.level.isClientSide) {
        ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
        Mekanism.packetHandler.sendTo(new PacketSecurityUpdate(), serverPlayer);
        player.getCapability(Capabilities.RADIATION_ENTITY_CAPABILITY).ifPresent(c -> PacketRadiationData.sync(serverPlayer));
        player.inventoryMenu.addSlotListener(new VanillaGhostStackSyncFix(serverPlayer));
    }
}
Also used : VanillaGhostStackSyncFix(mekanism.common.inventory.container.VanillaGhostStackSyncFix) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with PacketSecurityUpdate

use of mekanism.common.network.to_client.PacketSecurityUpdate in project Mekanism by mekanism.

the class SecurityUtils method claimItem.

public static void claimItem(PlayerEntity player, ItemStack stack) {
    if (stack.getItem() instanceof IOwnerItem) {
        ((IOwnerItem) stack.getItem()).setOwnerUUID(stack, player.getUUID());
        Mekanism.packetHandler.sendToAll(new PacketSecurityUpdate(player.getUUID(), null));
        player.sendMessage(MekanismUtils.logFormat(MekanismLang.NOW_OWN), Util.NIL_UUID);
    }
}
Also used : IOwnerItem(mekanism.common.lib.security.IOwnerItem) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate)

Example 3 with PacketSecurityUpdate

use of mekanism.common.network.to_client.PacketSecurityUpdate in project Mekanism by mekanism.

the class BlockMekanism method setPlacedBy.

@Override
public void setPlacedBy(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity placer, @Nonnull ItemStack stack) {
    super.setPlacedBy(world, pos, state, placer, stack);
    TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, world, pos);
    if (tile == null) {
        return;
    }
    if (tile.supportsRedstone()) {
        tile.redstone = world.hasNeighborSignal(pos);
    }
    tile.onPlace();
    // Handle item
    Item item = stack.getItem();
    setTileData(world, pos, state, placer, stack, tile);
    // but there is a good chance a lot of this stuff has no real reason to need to be set on the client side at all
    if (!world.isClientSide && tile.getFrequencyComponent().hasCustomFrequencies()) {
        tile.getFrequencyComponent().read(ItemDataUtils.getDataMap(stack));
    }
    if (tile instanceof TileEntitySecurityDesk && placer != null) {
        tile.getSecurity().setOwnerUUID(placer.getUUID());
    }
    if (item instanceof ISecurityItem && tile.hasSecurity()) {
        ISecurityItem securityItem = (ISecurityItem) item;
        tile.setSecurityMode(securityItem.getSecurity(stack));
        UUID ownerUUID = securityItem.getOwnerUUID(stack);
        if (ownerUUID != null) {
            tile.getSecurity().setOwnerUUID(ownerUUID);
        } else if (placer != null) {
            tile.getSecurity().setOwnerUUID(placer.getUUID());
            if (!world.isClientSide) {
                // If the machine doesn't already have an owner, make sure we portray this
                Mekanism.packetHandler.sendToAll(new PacketSecurityUpdate(placer.getUUID(), null));
            }
        }
    }
    if (tile.supportsUpgrades()) {
        // The read method validates that data is stored
        tile.getComponent().read(ItemDataUtils.getDataMap(stack));
    }
    if (tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        // The read methods validate that data is stored
        config.getConfig().read(ItemDataUtils.getDataMap(stack));
        config.getEjector().read(ItemDataUtils.getDataMap(stack));
    }
    for (SubstanceType type : EnumUtils.SUBSTANCES) {
        if (type.canHandle(tile)) {
            DataHandlerUtils.readContainers(type.getContainers(tile), ItemDataUtils.getList(stack, type.getContainerTag()));
        }
    }
    if (tile instanceof ISustainedData && stack.hasTag()) {
        ((ISustainedData) tile).readSustainedData(stack);
    }
    if (tile.supportsRedstone() && ItemDataUtils.hasData(stack, NBTConstants.CONTROL_TYPE, NBT.TAG_INT)) {
        tile.setControlType(RedstoneControl.byIndexStatic(ItemDataUtils.getInt(stack, NBTConstants.CONTROL_TYPE)));
    }
    if (item instanceof ISustainedInventory && tile.persistInventory()) {
        tile.setInventory(((ISustainedInventory) item).getInventory(stack));
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Item(net.minecraft.item.Item) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISustainedInventory(mekanism.common.tile.interfaces.ISustainedInventory) SubstanceType(mekanism.common.tile.base.SubstanceType) TileEntitySecurityDesk(mekanism.common.tile.TileEntitySecurityDesk) UUID(java.util.UUID) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Example 4 with PacketSecurityUpdate

use of mekanism.common.network.to_client.PacketSecurityUpdate in project Mekanism by mekanism.

the class TileEntitySecurityDesk method setSecurityDeskMode.

public void setSecurityDeskMode(SecurityMode mode) {
    SecurityFrequency frequency = getFreq();
    if (frequency != null) {
        SecurityMode old = frequency.getSecurityMode();
        if (old != mode) {
            frequency.setSecurityMode(mode);
            markDirty(false);
            // send the security update to other players; this change will be visible on machine security tabs
            Mekanism.packetHandler.sendToAll(new PacketSecurityUpdate(frequency.getOwner(), new SecurityData(frequency)));
            if (old == SecurityMode.PUBLIC || (old == SecurityMode.TRUSTED && mode == SecurityMode.PRIVATE)) {
                validateAccess();
            }
        }
    }
}
Also used : SecurityFrequency(mekanism.common.lib.security.SecurityFrequency) SecurityMode(mekanism.common.lib.security.SecurityMode) SecurityData(mekanism.common.lib.security.SecurityData) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate)

Example 5 with PacketSecurityUpdate

use of mekanism.common.network.to_client.PacketSecurityUpdate in project Mekanism by mekanism.

the class TileEntitySecurityDesk method toggleOverride.

/**
 * Only call on the server side
 */
public void toggleOverride() {
    SecurityFrequency frequency = getFreq();
    if (frequency != null) {
        frequency.setOverridden(!frequency.isOverridden());
        markDirty(false);
        // send the security update to other players; this change will be visible on machine security tabs
        Mekanism.packetHandler.sendToAll(new PacketSecurityUpdate(frequency.getOwner(), new SecurityData(frequency)));
        validateAccess();
    }
}
Also used : SecurityFrequency(mekanism.common.lib.security.SecurityFrequency) SecurityData(mekanism.common.lib.security.SecurityData) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate)

Aggregations

PacketSecurityUpdate (mekanism.common.network.to_client.PacketSecurityUpdate)6 UUID (java.util.UUID)2 SecurityData (mekanism.common.lib.security.SecurityData)2 SecurityFrequency (mekanism.common.lib.security.SecurityFrequency)2 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Nonnull (javax.annotation.Nonnull)1 IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 EntityRobit (mekanism.common.entity.EntityRobit)1 VanillaGhostStackSyncFix (mekanism.common.inventory.container.VanillaGhostStackSyncFix)1 IOwnerItem (mekanism.common.lib.security.IOwnerItem)1 ISecurityItem (mekanism.common.lib.security.ISecurityItem)1 SecurityMode (mekanism.common.lib.security.SecurityMode)1 TileEntitySecurityDesk (mekanism.common.tile.TileEntitySecurityDesk)1 SubstanceType (mekanism.common.tile.base.SubstanceType)1 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)1 ISustainedData (mekanism.common.tile.interfaces.ISustainedData)1 ISustainedInventory (mekanism.common.tile.interfaces.ISustainedInventory)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Item (net.minecraft.item.Item)1