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));
}
}
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);
}
}
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));
}
}
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();
}
}
}
}
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();
}
}
Aggregations