use of mekanism.common.lib.frequency.IFrequencyItem in project Mekanism by mekanism.
the class MekanismUtils method addFrequencyItemTooltip.
/**
* @apiNote Only call on the client.
*/
public static void addFrequencyItemTooltip(ItemStack stack, List<ITextComponent> tooltip) {
FrequencyIdentity frequency = ((IFrequencyItem) stack.getItem()).getFrequencyIdentity(stack);
if (frequency != null) {
tooltip.add(MekanismLang.FREQUENCY.translateColored(EnumColor.INDIGO, EnumColor.GRAY, frequency.getKey()));
CompoundNBT frequencyCompound = ItemDataUtils.getCompound(stack, NBTConstants.FREQUENCY);
if (frequencyCompound.hasUUID(NBTConstants.OWNER_UUID)) {
String owner = OwnerDisplay.getOwnerName(MekanismClient.tryGetClientPlayer(), frequencyCompound.getUUID(NBTConstants.OWNER_UUID), null);
if (owner != null) {
tooltip.add(MekanismLang.OWNER.translateColored(EnumColor.INDIGO, EnumColor.GRAY, owner));
}
}
tooltip.add(MekanismLang.MODE.translateColored(EnumColor.INDIGO, EnumColor.GRAY, frequency.isPublic() ? MekanismLang.PUBLIC : MekanismLang.PRIVATE));
}
}
use of mekanism.common.lib.frequency.IFrequencyItem in project Mekanism by mekanism.
the class PacketGuiSetFrequency method handle.
@Override
public void handle(NetworkEvent.Context context) {
ServerPlayerEntity player = context.getSender();
if (player == null) {
return;
}
if (updateType.isTile()) {
TileEntity tile = WorldUtils.getTileEntity(player.level, tilePosition);
if (SecurityUtils.canAccess(player, tile) && tile instanceof IFrequencyHandler) {
if (updateType == FrequencyUpdate.SET_TILE) {
((IFrequencyHandler) tile).setFrequency(type, data, player.getUUID());
} else if (updateType == FrequencyUpdate.REMOVE_TILE) {
((IFrequencyHandler) tile).removeFrequency(type, data, player.getUUID());
}
}
} else {
ItemStack stack = player.getItemInHand(currentHand);
if (SecurityUtils.canAccess(player, stack) && stack.getItem() instanceof IFrequencyItem) {
IFrequencyItem item = (IFrequencyItem) stack.getItem();
FrequencyManager<FREQ> manager = type.getManager(data, player.getUUID());
if (updateType == FrequencyUpdate.SET_ITEM) {
// Note: We don't bother validating if the frequency is public or not here, as if it isn't then
// a new private frequency will just be created for the player who sent a packet they shouldn't
// have been able to send due to not knowing what private frequencies exist for other players
item.setFrequency(stack, manager.getOrCreateFrequency(data, player.getUUID()));
} else if (updateType == FrequencyUpdate.REMOVE_ITEM) {
if (manager.remove(data.getKey(), player.getUUID())) {
FrequencyIdentity current = item.getFrequencyIdentity(stack);
if (current != null && current.equals(data)) {
// If the frequency we are removing matches the stored frequency set it to nothing
item.setFrequency(stack, null);
}
}
}
}
}
}
Aggregations